ASP.NET 中值类型集合的声明性语法?

发布于 2024-09-10 09:35:13 字数 875 浏览 3 评论 0原文

我知道在 ASP.NET(这里主要讨论 2.0)中,可以在一个对象上设置一个属性,该对象接受一组事物(我猜是一个可枚举类型是触发器),然后以声明方式引用它。例如:

<ObjectDataSource properties="blahblahblah">
    <SelectParameters>
        <asp:Parameter />
    </SelectParameters>
</ObjectDataSource>

部分是我问题的根源。假设我想要一个更简单的类型集合。假设一个 List ,或者如果泛型已经存在,则假设一个 IntegerCollection 或 StringCollection。我将如何声明性地使用它?是否允许 ,或者我可以将原始值放入其中,例如 string, string, string 或什么?

编辑:

我觉得我的问题不够清楚。据我了解,ObjectDataSource 将其 SelectParameters 属性实现为ParametersCollection,并且可以以声明方式(在 ASPX 页面中)使用该属性来设置该集合中的参数类型。我想知道的是,如果我将 StringCollection 之类的东西作为另一个控件的属性,是否有语法(在 ASPX 中)用于将字符串添加到该集合?或者我是否必须定义一个包装类,例如 DropDownList 如何采用 ListItems 来填充其集合?

I know that in ASP.NET (talking about 2.0 here primarily) one can set a property on an object that takes a collection of things (an enumerable type I'm guessing is the trigger) and then reference it declaritivly. For example:

<ObjectDataSource properties="blahblahblah">
    <SelectParameters>
        <asp:Parameter />
    </SelectParameters>
</ObjectDataSource>

It is the <asp:Parameter /> part which is the root of my question. Say I wanted a simpler collection on a type. Say a List<String> or if generics are out, an IntegerCollection or StringCollection. How would I use that declaratively? Is <string value=''> allowed, or can I put raw values into it like <StringCollection>string, string, string</StringCollection> or what?

EDIT:

I feel like I was not clear enough in my question. I understand that ObjectDataSource implements its SelectParameters property as a ParametersCollection, and that one can use that property declaratively (in an ASPX page) to set up Parameter types within that collection. What I'm wondering is if I made something like StringCollection as a property on another control, is there a syntax (in ASPX) for adding strings to that collection? Or would I have to define a wrapping class like how DropDownList takes ListItems to fill its collection?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不必你懂 2024-09-17 09:35:13

在对象数据源中,选择参数指的是返回集合的方法中的参数。该参数必须是可以从字符串转换的东西,它不能是集合或数组。

In an objectdatasource the selectparameter refers to a parameter in a method that returns a collection. That parameter needs to be something that can be converted from a string, it cannot be a collection or an array.

爱你不解释 2024-09-17 09:35:13

我最终找到了我需要的东西。一般答案是在属性上使用 TypeConverter 属性。 GridView 使用(作为一个示例)DataKeyNames 来完成此操作,将字符串中以逗号分隔的名称列表转换为字符串数组。

I eventually found what I needed for this. The general answer is to use a TypeConverter attribute on the property. The GridView does this with (as one example) DataKeyNames, converting a comma separated list of names in a string into an array of strings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文