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
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.
<asp:repeater id="whatever" runat=server>
<ItemTemplate>First Name: <%# DataBinder.Eval(Container.DataItem,"FirstName") %></ItemTemplate>
</asp:repeater>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With