.Net Repeater 相当于单个对象?
有人可以尝试推荐解决以下请求的最佳行动理由:
我使用 Repeater 类作为基础创建了许多扩展类,并且喜欢这样做的灵活性、易用性和结果。 我现在想做的是为单个对象创建一个类似的自定义 Web 控件(即数据源未实现 IListSource 或 IEnumerable)。 我已经通过扩展中继器创建了我想要实现的结构,然后在设置数据源时使用 1 项的列表来保存对象,然后进行数据绑定。
e.g a rough example:
Dim oObj as New MyObject(1)
Dim gl As New Generic.List(of MyObiect)()
gl.Add(oObj)
rpt.DataSource = gl
rpt.DataBind()
这看起来确实像是围绕事物的一个小技巧,我希望能够执行以下操作:
e.g new call, where my control is the new custom control:
Dim oObj as New MyObject(1)
myControl.DataSource = oObj
myControl.DataBind()
我希望能够使用各种变量和属性定义此自定义控件,其结果将启用以下类型的布局:
<My:ObjControl ID="frm" runat="server">
<Tabs>
<My:Tab name="Details">
<Items>
<My:Item Type="Text" Label="First Name" Property="FirstName" />
<My:Item Type="Text" Label="Last Name" Property="LastName" />
<My:Item Type="Text" Label="Title" Property="Title" />
</Items>
</Tab>
<My:Tab name="Address">
<Items>
<My:Item Type="Text" Label="Address 1" Property="Address1" />
<My:Item Type="Text" Label="Address 2" Property="Address2" />
<My:Item Type="Text" Label="Address 3" Property="Address3" />
</Items>
</Tab>
</Tabs>
</My:ObjControl>
此实现必须使用 WebForms 进行,尽管考虑到上述情况,使用 MVC 似乎是理想的方法。 通过这样做,我想创建一个灵活的 WebControl,它使用反射(可用于实现特定接口的所有类),每次需要时,它将生成所需的表单,只需后面(上面)的三行代码。
我是否应该向自定义转发器 (DataObject) 添加一个属性,该转发器接受一个对象并相应地设置数据源并节省时间? 或者,还有更好的方法?
希望这一切都有道理!
干杯, 史蒂夫
Could someone try to recommend the best cause of action to solve the request below:
I have created a number of extended classes using the Repeater class as a Base and love the flexibility, the ease and the results of doing this. What I want to to do now is to make a similar Custom Web Control for a single object (i.e the DataSource not implementing a IListSource or IEnumerable). I have created the structure of what I'm trying to achieve by extending the repeater and then when setting the datasource using a list of 1 item to hold the object and then databinding.
e.g a rough example:
Dim oObj as New MyObject(1)
Dim gl As New Generic.List(of MyObiect)()
gl.Add(oObj)
rpt.DataSource = gl
rpt.DataBind()
This does seem like a small hack around things, what I would like to be able to do is the following:
e.g new call, where my control is the new custom control:
Dim oObj as New MyObject(1)
myControl.DataSource = oObj
myControl.DataBind()
I want to able to define this custom control with various variables and properties, the result of which will enable the following type of layout:
<My:ObjControl ID="frm" runat="server">
<Tabs>
<My:Tab name="Details">
<Items>
<My:Item Type="Text" Label="First Name" Property="FirstName" />
<My:Item Type="Text" Label="Last Name" Property="LastName" />
<My:Item Type="Text" Label="Title" Property="Title" />
</Items>
</Tab>
<My:Tab name="Address">
<Items>
<My:Item Type="Text" Label="Address 1" Property="Address1" />
<My:Item Type="Text" Label="Address 2" Property="Address2" />
<My:Item Type="Text" Label="Address 3" Property="Address3" />
</Items>
</Tab>
</Tabs>
</My:ObjControl>
This implementation has to take place using WebForms, although it looks like using MVC would be the ideal approach considering the above. By doing this I want to create a flexible WebControl that uses reflection (that can be used for all classes that implement a specific interface) which will generate the required form with only the three lines of code behind (above) each time it's needed.
Should I just add a property to a custom repeater (DataObject) that takes an object and sets the DataSource accordingly and saving my time? Or is there a better way?
Hope this all makes sense!
Cheers,
Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正试图努力回避中继器需要一个列表而您想为其提供 1 个实例这一事实。 只需将其包装在新的 List* oObj 中即可,然后继续。 一直都是这么做的。
我当然不知道他们的自定义服务器控件到底发生了什么。 在我看来你又太努力了。
You're trying way to hard to get around the fact that the repeater wants an List and you want to give it 1 instance. Just wrap it in a new List* oObj ) and move on. It's done all the time.
I certainly dunno what they heck is going on with that custom server control. Seems to me you are trying too hard again.