|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ASP:TableRow with dynamic designI have a repeater and want to set design on table row based on data values.
I found the <ASP:TableRow> which is a good candidate, but then I am forced to have the <ASP:Table> tags within the ItemTemplate! This is very stupid, because then I will have no correlation of the columns in the header and the items. It worked fine to seperate the tags when I used normal <Table> and <TR> tags. Can I set background color or foreground color on a <TR> from code? Yes, you can. Try something like this:
<asp:Repeater ID="Repeater1" runat="server" OnItemCreated ="Repeater1_ItemCreated"> <HeaderTemplate> <table > <thead> <tr runat="server" id="tr0"> <th runat="server" id="td0"> Table header Column </th> </tr> </thead> </HeaderTemplate> <ItemTemplate> <tbody> <tr runat="server" id="row1"> <td runat="server" id="td1"> <asp:Label ID="lblCompany" runat="server" Text='<%# Eval("FieldName") %>'></asp:Label> </td> </tr> </tbody> </ItemTemplate> <FooterTemplate > </table> </FooterTemplate> </asp:Repeater> and in the codebehind you can acces the HTMLTableRows to change their style based on data like this: protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { HtmlTableRow row1 = (HtmlTableRow)e.Item.FindControl("row1"); if (row1 != null) { //chane the style based on the data row1.Attributes.Add("class", "MyClass"); } } } Show quoteHide quote "Jakob Lithner" wrote: > I have a repeater and want to set design on table row based on data values. > I found the <ASP:TableRow> which is a good candidate, but then I am forced > to have the <ASP:Table> tags within the ItemTemplate! > This is very stupid, because then I will have no correlation of the columns > in the header and the items. It worked fine to seperate the tags when I used > normal <Table> and <TR> tags. > Can I set background color or foreground color on a <TR> from code? Correction:
------------ the <tbody> section should have been split between the <HeaderTemplate> and the <ItemTemplate> in the code posted below. Show quoteHide quote "Phillip Williams" wrote: > Yes, you can. Try something like this: > <asp:Repeater ID="Repeater1" runat="server" OnItemCreated > ="Repeater1_ItemCreated"> > <HeaderTemplate> > <table > > <thead> > <tr runat="server" id="tr0"> > <th runat="server" id="td0"> > Table header Column > </th> > </tr> > </thead> > </HeaderTemplate> > <ItemTemplate> > <tbody> > <tr runat="server" id="row1"> > <td runat="server" id="td1"> > <asp:Label ID="lblCompany" runat="server" Text='<%# > Eval("FieldName") %>'></asp:Label> > </td> > </tr> > </tbody> > </ItemTemplate> > <FooterTemplate > > </table> > </FooterTemplate> > </asp:Repeater> > > and in the codebehind you can acces the HTMLTableRows to change their style > based on data like this: > > protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e) > { > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == > ListItemType.AlternatingItem) > { > HtmlTableRow row1 = (HtmlTableRow)e.Item.FindControl("row1"); > if (row1 != null) > { > //chane the style based on the data > row1.Attributes.Add("class", "MyClass"); > } > } > } > -- > HTH, > Phillip Williams > http://www.societopia.net > http://www.webswapp.com > > > "Jakob Lithner" wrote: > > > I have a repeater and want to set design on table row based on data values. > > I found the <ASP:TableRow> which is a good candidate, but then I am forced > > to have the <ASP:Table> tags within the ItemTemplate! > > This is very stupid, because then I will have no correlation of the columns > > in the header and the items. It worked fine to seperate the tags when I used > > normal <Table> and <TR> tags. > > Can I set background color or foreground color on a <TR> from code?
Other interesting topics
Books on ASP.net 2.0
Problem compiling remote web in VS2005 WebPartManager: disable Personalization and still use WebPartManger.AddWebPart() WebPartManager.AddWebPart...not understanding exception Asp.net And Firefox dynamic column/fields Using RSS Why Publish take so long? Memebership, Role, Profile Provider how can i refresh my aspx webform |
|||||||||||||||||||||||