ASP.NET 中值类型集合的声明性语法?
我知道在 ASP.NET(这里主要讨论 2.0)中,可以在一个对象上设置一个属性,该对象接受一组事物(我猜是一个可枚举类型是触发器),然后以声明方式引用它。例如:
<ObjectDataSource properties="blahblahblah">
<SelectParameters>
<asp:Parameter />
</SelectParameters>
</ObjectDataSource>
部分是我问题的根源。假设我想要一个更简单的类型集合。假设一个 List
,或者如果泛型已经存在,则假设一个 IntegerCollection 或 StringCollection。我将如何声明性地使用它?是否允许
,或者我可以将原始值放入其中,例如
或什么?
编辑:
我觉得我的问题不够清楚。据我了解,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在对象数据源中,选择参数指的是返回集合的方法中的参数。该参数必须是可以从字符串转换的东西,它不能是集合或数组。
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.
我最终找到了我需要的东西。一般答案是在属性上使用 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.