From: Axel on
Hi,

I have found an article on Web User Controls in Repeaters with DataList

http://www.c-sharpcorner.com/UploadFile/Mike%20Clark/PartA02272007012412AM/PartA.aspx

, thanks very much.

I am currently trying to incorporate a web user control for generating
web content via a GenericList. I have managed to do all the coding for
all the detail, have a lovely web user control coded, but I am binding
to the Datasource in the Page_Load event of the container code:



private Product _Product;

if (_Product.hasMasterAttributes)
{
this.repeatAttributes.DataSource = _Product.masterAttributeList;
}

the Product class contains a Generic List of ProductAttribute class
instances. (ProductAttribute is a very simple class which just serves as
strongly typed container for my attributes).

I am exposing the various attributes of ProductAttribute (such as
ContentText, URL etc) as properties and also I have same public
properties in the Web User Control in order to marshall data from the
ProductAttribute instance to the Web User Control. What I am having real
difficulty with is the actual binding of these attributes within the
ItemTemplate, also I do not like using the server code on the asp page
(especially since I can not debug what is happening) - do you know if
it is possible to use an event for binding these?

<asp:Repeater ID="repeatAttributes" runat="server"
onitemdatabound="repeatAttributes_ItemDataBound"
onitemcreated="repeatAttributes_ItemCreated" >
<ItemTemplate >
<uc1:EditAttributePanel ID="theAttributePanel"
runat="server"


ContentTitle="<%#DataBinder.Eval(Container.DataItem,"ContentTitle")%>"
Language = "<%#DataBinder.Eval(Container.DataItem,"LanguageId")%>"
Attribute = "<%#DataBinder.Eval(Container.DataItem,"AttributeCount")%>"



/>
</ItemTemplate>
</asp:Repeater>

I had quite great toruble with the lines for copying data from the
container List to the properties of the Web User Control (see 3 lkinbes
above in the stripped down example above) lots of runtime compile
errors, and I don't really like that code polluting the aspx file. Also
now that the page is not crashing anymore, it doesn't show anything in
the Repeater, although my generic lists definitelyt contain data; where
can I check what data is being marshalled into the repeater?

I would prefer doing all the copying of data between List Item and web
control instance from code, which would give me more control and I could
add validation, is there an event I can use for this???

Another feature that my project provides is a localization interface so
the Product actually contains 2 Generic Lists of Attributes (one for the
Master Language and one for the current translation), which is another
reason that I would like to have the databinding in C# code and not on
the container page itself.

thanks in advance
Axel