Repeater with Datalist - quick help needed for tomorrow's presentation

A

Axel

Hi,

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

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


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 (and not
on the aspx page) - as only in the Page Load event the attribute list is
populated:



==== page containing the repeater (excerpt) ===
private Product _Product;

Page_Load ...
if (_Product.hasMasterAttributes) {
if (Language == MasterLanguage)
this.repeatAttributes.DataSource = _Product.masterAttributeList;
else
this.repeatAttributes.DataSource = _Product.localizedAttributeList;
}


=== product class (excerpt) ====
// the constructor fills the attributes from the database
// these generic lists shall be used as DataSource for the repeater
public List<ProductAttribute> masterAttributeList
= new List<ProductAttribute>();
public List<ProductAttribute> localizedAttributeList
= new List<ProductAttribute>();

public Int16 ProductStatus { get.. let...};
public int localizedLanguageId=0;

=== ProductAttribute class; these are the items in the generic List ===
public class ProductAttribute
{
// lazy interface a la 'struct'
public int ProductId;
public int LanguageId;
public int AttributeCount;
public string ContentTitle;
public string ContentType;
public string ContentText;
public string AltText;
public string ToolTipText;
public string URI;
public int SequenceCount;


public ProductAttribute (int lProductId, int lLanguageId, int
lAttributeCount, string sContentTitle, string sContentType, string
sContentText, string sAltText, string sToolTipText, string sURI, int
lSequenceCount)
{
this.ProductId = lProductId;
this.LanguageId =lLanguageId;
this.AttributeCount = lAttributeCount;

this.ContentTitle = sContentTitle;
this.ContentType = sContentType;
this.ContentText = sContentText;
this.AltText = sAltText;
this.ToolTipText = sToolTipText;
this.URI = sURI;

this.SequenceCount = lSequenceCount;
}
}





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 trouble 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?

Also, can I re-trigger the databinding for the repeater from an
interface of the repeater from code? (Did not find any DataBind() interface)

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??? Or can I replace
the awkward DataBinder.Eval stuff with some public methods on my page??

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top