alternating item style in template row with table tags

Discussion in 'ASP .Net Datagrid Control' started by NancyASAP, Jul 12, 2005.

  1. NancyASAP

    NancyASAP Guest

    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
    NancyASAP, Jul 12, 2005
    #1
    1. Advertising

  2. Hi Nancy

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

    Regards
    Fiaz Ali Saleemi
    Fiaz Ali Saleemi, Jul 14, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob
    Replies:
    4
    Views:
    5,598
    mayank1987
    Mar 10, 2011
  2. =?Utf-8?B?TWF4IFdlZWJsZXI=?=

    Alternating Item Style "ForeColor" not working in Template Column

    =?Utf-8?B?TWF4IFdlZWJsZXI=?=, Oct 26, 2005, in forum: ASP .Net
    Replies:
    9
    Views:
    916
    =?Utf-8?B?TWF4IFdlZWJsZXI=?=
    Oct 27, 2005
  3. Ralph Snart
    Replies:
    2
    Views:
    773
    Ralph Snart
    Aug 3, 2003
  4. Guest
    Replies:
    5
    Views:
    1,707
    Eliyahu Goldin
    Jul 13, 2006
  5. Replies:
    4
    Views:
    935
Loading...

Share This Page