Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Web User Controls in Repeaters with DataList

Reply
Thread Tools

Web User Controls in Repeaters with DataList

 
 
Axel
Guest
Posts: n/a
 
      04-20-2010
Hi,

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

http://www.c-sharpcorner.com/UploadF...2AM/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.DataIte m,"ContentTitle")%>"
Language = "<%#DataBinder.Eval(Container.DataItem,"LanguageId ")%>"
Attribute = "<%#DataBinder.Eval(Container.DataItem,"AttributeC ount")%>"



/>
</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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Repeaters, Dynamic controls, and postback schiavonir ASP .Net 1 03-25-2009 02:52 PM
Repeaters, Controls and Events LandShark ASP .Net 0 07-24-2007 07:46 PM
Controls in repeaters MattB ASP .Net 3 07-23-2007 09:04 PM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM
IntelliSense on Web User Controls and Web Custom Controls Axel Dahmen ASP .Net 1 11-12-2003 06:12 AM



Advertisments