473,487 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ASP:TableRow with dynamic design

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?
Jan 7 '06 #1
3 4237
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?

Jan 7 '06 #2
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?

Jan 7 '06 #3
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!

Jan 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1402
by: Roland Hall | last post by:
If I wanted to write my own blog application, what functionality should it contain? TIA... -- Roland Hall /* This information is distributed in the hope that it will be useful, but without...
2
1768
by: Coleen | last post by:
Hi all :-) I have the following code, and need it to break specifically at a point in the span, but I am unable to get it to break exactly where I want it to. <asp:TableCell CssClass="table"...
0
1389
by: Kristoffer Arfvidson | last post by:
HI! I have the following javascript events in my normal tables. onMouseOver,onMouseOut and onClick Now, when I try to put this in my asp:tablerow it just gets an error msg that literal text is...
2
3701
by: Tim::.. | last post by:
Hi can someone tell me where I might be able to get some information on creating a dynamic ASP.NET menu which is populated by a database and has child nodes under main catagouries I wan to produce...
0
2295
by: msquaredonline | last post by:
I have an ASP page that loops through a database and adds up score results (that were received from a Flash survey I created) and adds up the number of results (to be later used to determine the...
2
1782
by: keithb | last post by:
I'm just learning ASP.NET 2.0, so I apologize for asking a question which probably has an obvious answer. The Standard toolbox in VS2K5 has a control called Table. Placing the control on a web page...
0
859
by: Barb | last post by:
Has anyone seen this happen? I have pages with <asp:Textbox> and <asp:DropDownList> controls on them. Some of them display differently. Some are recessed with the left & top borders being gray...
0
1514
by: astropup | last post by:
Can someone post a link to general guidelines for making a dynamic ASP site google-friendly? I am looking at building a product support web site for a company. I want to dynamically generate...
0
895
by: tcv | last post by:
Hello all, Can some of you refresh my memory on a) how to populate an HTML table cell with some values generated by a javascript above Body section b) how to code in asp.net to change table...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5442
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4874
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.