473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Alternating row colors on an "ordinary" table in ASP.NET 2

I'm making admin forms. I'm wondering if there is a way to have the server
programmatically assign alternating colors in a regular table (not a
datalist control). I notice ASP.NET 2 offers a runat="server" attribute on
tables, leading me to believe that this should be possible.

Any ideas? I'm using C#.

Thanks,
-KF
Jul 12 '06 #1
5 3325
Hello KF,

You have surmised correctly. Using the runat="server" and giving the table
an ID allows you to access it in server side code. HtmlTable's are composed
of a HtmlTableRowCollection's. Iterating through the HtmlTableRowCollection
items will allow you to set the background for the row through the BgColor
property:

// Iterate through the rows of the table.
for (int i = 0; i <= Table1.Rows.Count - 1; i++)
{

// Update the properties of each row.
Table1.Rows[i].BgColor = BgColorSelect.Value;
Table1.Rows[i].BorderColor = BorderColorSelect.Value;
Table1.Rows[i].Height = HeightSelect.Value;

}

Futhermore, you can iterate through the the table cells of the row as well
and set properties for each cell (if you so wish).
--
enjoy - brians
http://www.limbertech.com
"ke*****@nospam.nospam" wrote:
I'm making admin forms. I'm wondering if there is a way to have the server
programmatically assign alternating colors in a regular table (not a
datalist control). I notice ASP.NET 2 offers a runat="server" attribute on
tables, leading me to believe that this should be possible.

Any ideas? I'm using C#.

Thanks,
-KF
Jul 12 '06 #2
Sure. You just build an HtmlTable from scratch, and assign a different
background color to each HtmlTableRow as you add it.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.
<ke*****@nospam.nospamwrote in message
news:uV**************@TK2MSFTNGP03.phx.gbl...
I'm making admin forms. I'm wondering if there is a way to have the server
programmatically assign alternating colors in a regular table (not a
datalist control). I notice ASP.NET 2 offers a runat="server" attribute on
tables, leading me to believe that this should be possible.

Any ideas? I'm using C#.

Thanks,
-KF

Jul 12 '06 #3
Create a CSS class to represent the odd or even records. Then during your
building of the table assign the approprate class to the TR tag's class
property. This will require you to keep track of if the current record is
even or odd.

--
-Demetri
"ke*****@nospam.nospam" wrote:
I'm making admin forms. I'm wondering if there is a way to have the server
programmatically assign alternating colors in a regular table (not a
datalist control). I notice ASP.NET 2 offers a runat="server" attribute on
tables, leading me to believe that this should be possible.

Any ideas? I'm using C#.

Thanks,
-KF
Jul 12 '06 #4
Very complete answer, thank you very much, Brians.

-KF
"brians[MCSD]" <br********@discussions.microsoft.comwrote in message
news:01**********************************@microsof t.com...
Hello KF,

You have surmised correctly. Using the runat="server" and giving the table
an ID allows you to access it in server side code. HtmlTable's are
composed
of a HtmlTableRowCollection's. Iterating through the
HtmlTableRowCollection
items will allow you to set the background for the row through the BgColor
property:

// Iterate through the rows of the table.
for (int i = 0; i <= Table1.Rows.Count - 1; i++)
{

// Update the properties of each row.
Table1.Rows[i].BgColor = BgColorSelect.Value;
Table1.Rows[i].BorderColor = BorderColorSelect.Value;
Table1.Rows[i].Height = HeightSelect.Value;

}

Futhermore, you can iterate through the the table cells of the row as well
and set properties for each cell (if you so wish).
--
enjoy - brians
http://www.limbertech.com
"ke*****@nospam.nospam" wrote:
>I'm making admin forms. I'm wondering if there is a way to have the
server
programmatically assign alternating colors in a regular table (not a
datalist control). I notice ASP.NET 2 offers a runat="server" attribute
on
tables, leading me to believe that this should be possible.

Any ideas? I'm using C#.

Thanks,
-KF

Jul 12 '06 #5
A good place for this sort of things is PreRender event.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

"brians[MCSD]" <br********@discussions.microsoft.comwrote in message
news:01**********************************@microsof t.com...
Hello KF,

You have surmised correctly. Using the runat="server" and giving the table
an ID allows you to access it in server side code. HtmlTable's are
composed
of a HtmlTableRowCollection's. Iterating through the
HtmlTableRowCollection
items will allow you to set the background for the row through the BgColor
property:

// Iterate through the rows of the table.
for (int i = 0; i <= Table1.Rows.Count - 1; i++)
{

// Update the properties of each row.
Table1.Rows[i].BgColor = BgColorSelect.Value;
Table1.Rows[i].BorderColor = BorderColorSelect.Value;
Table1.Rows[i].Height = HeightSelect.Value;

}

Futhermore, you can iterate through the the table cells of the row as well
and set properties for each cell (if you so wish).
--
enjoy - brians
http://www.limbertech.com
"ke*****@nospam.nospam" wrote:
>I'm making admin forms. I'm wondering if there is a way to have the
server
programmatically assign alternating colors in a regular table (not a
datalist control). I notice ASP.NET 2 offers a runat="server" attribute
on
tables, leading me to believe that this should be possible.

Any ideas? I'm using C#.

Thanks,
-KF

Jul 13 '06 #6

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

Similar topics

15
by: Jordan Rastrick | last post by:
First, a disclaimer. I am a second year Maths and Computer Science undergraduate, and this is my first time ever on Usenet (I guess I'm part of the http generation). On top of that, I have been...
8
by: Mario T. Lanza | last post by:
I'm not sure what I'm doing wrong. I have a form that has mnay input fields. Before each input field is a label enclosed in custom LABEL tags. Inside my CSS I have: LABEL { width: 120px; }
388
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's...
12
by: Emi Lu | last post by:
Hello all, I have a question about "date" & "timestamp" types in PostgreSQL. I want to setup the default value '0000-00-00' and "0000-00-00 00:00:00" for them. However, it seems that PostgreSQL...
34
by: Frederick Gotham | last post by:
Is the domestic usage of the C "for" loop inefficient when it comes to simple incrementation? Here's a very simple program that prints out the bit-numbers in a byte. #include <stdio.h> #include...
10
by: lovecreatesbeauty | last post by:
Is parameter type conversion required for the 2nd argument on printf("%p", (void *)&i); ? But one would never call memcpy like: memcpy((void *)pi, (void *)pj, sizeof *pj); /*memcpy((void *)pi,...
30
by: josh | last post by:
Hi all, what does it meaning that strange sintax (look at the object :) ? if I have i.e. array.length I can use array. and is it IE/Firefox compatible??
13
by: donpro | last post by:
Hi, I have a row of 5 <DIVelements that have the "float: left" attribute as I wanted them on the same row. I issue a "clear: left" for the subsequent element. All looks great except if I...
19
by: maya | last post by:
hi, so what is "modern" javascript?? the same as "DOM-scripting"? i.e., editing content (or changing appearance of content) dynamically by massaging javascript objects, html elements, etc? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.