alternating item style in template row with table tags

N

NancyASAP

In case anyone else runs into this issue...

I recently wanted to set alternating item style on a grid row that
contained a template item for the entire row. This template item
contained html table tags. This allowed me to make each single grid row
a multiple row table (I needed each grid row to be 3 rows worth of
stuff).

However, when I tried to set alternating item style on the grid, row
background color was not visible because table row tags superceded it -
essentially were laying over the color so that it never showed.

To fix this, I had to dynamically set a background color on the
embedded html table rows in the datagrid template item. I gave the html
row tags <tr's> a unique id attribute (id=myid), and set the runat
attribute to server (runat=server). Both attributes are necessary! Then
in the grid ItemDataBound event, I put this code in (where "row1Valid"
was my unique <tr> tag id):

If e.Item.ItemType = ListItemType.AlternatingItem Then
Dim row As HtmlTableRow = CType(e.Item.FindControl("row1Valid"),
HtmlTableRow)
row.Style.Add("background-color", "#E0E0E0;")
End If

Put in the Style Add command for each tr tag in the item template.
Worked great! Hope this helps someone else.
Nancy Steinmann
MCSD .NET
 
F

Fiaz Ali Saleemi

Hi Nancy

Thanks for sharing your experience and knowledge this will definetly help.

Regards
Fiaz Ali Saleemi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top