Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP:TableRow with dynamic design

Reply
Thread Tools

ASP:TableRow with dynamic design

 
 
=?Utf-8?B?SmFrb2IgTGl0aG5lcg==?=
Guest
Posts: n/a
 
      01-07-2006
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?
 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      01-07-2006
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?

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      01-07-2006
Correction:
------------
the <tbody> section should have been split between the <HeaderTemplate> and
the <ItemTemplate> in the code posted below.

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

 
Reply With Quote
 
=?Utf-8?B?SmFrb2IgTGl0aG5lcg==?=
Guest
Posts: n/a
 
      01-07-2006
Beautiful!
I didn't know the HTML elements could be reached in code too ....
How easy it is when you know how to do it!

 
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
Class design/design pattern resources TomTom MCSD 2 10-09-2004 07:38 AM
OO design in servlet design question dave Java 5 07-17-2004 12:58 PM
Xilinx Schematic design vs VHDL code design ZackS VHDL 5 07-09-2004 07:51 AM
Looking for help/resources on Writing a nice detailed design / tech design for vb.net code SpamProof Java 3 12-01-2003 06:06 AM



Advertisments