Problems with GridView.CssClass and Selections

Discussion in 'ASP .Net' started by Jonathan Wood, May 11, 2008.

  1. Greetings,

    On a GridView control, I want to show alternating colors. But instead of
    alternating on each row, I want to alternate each group. So several items
    would be one color and the next several items would be another color.

    I'm able to accomplish this by setting the CssClass property in the
    GridView's RowDataBound event handler.

    But I also need the rows to be selectable so I set the CssClass for the
    SelectedRowStyle at design time. The problem is that, when CssClass is set
    in the RowDataBound event handler, that style is always used, even when the
    row is selected. And these rows no longer provide any visual indication that
    they are selected.

    It appears that ASP.NET will not override a manually set CssClass with the
    selected row CssClass.

    Does anyone know how I could make this work?

    Thanks.

    --
    Jonathan Wood
    SoftCircuits Programming
    http://www.softcircuits.com
     
    Jonathan Wood, May 11, 2008
    #1
    1. Advertising

  2. Jonathan Wood

    Stan Guest

    On 11 May, 17:42, "Jonathan Wood" <> wrote:
    > Greetings,
    >
    > On a GridView control, I want to show alternating colors. But instead of
    > alternating on each row, I want to alternate each group. So several items
    > would be one color and the next several items would be another color.
    >
    > I'm able to accomplish this by setting the CssClass property in the
    > GridView's RowDataBound event handler.
    >
    > But I also need the rows to be selectable so I set the CssClass for the
    > SelectedRowStyle at design time. The problem is that, when CssClass is set
    > in the RowDataBound event handler, that style is always used, even when the
    > row is selected. And these rows no longer provide any visual indication that
    > they are selected.
    >
    > It appears that ASP.NET will not override a manually set CssClass with the
    > selected row CssClass.
    >
    > Does anyone know how I could make this work?
    >
    > Thanks.
    >
    > --
    > Jonathan Wood
    > SoftCircuits Programminghttp://www.softcircuits.com


    As you are setting the normal styles at run time it is necessary to do
    the same the for the selected row. In the RowDatabound event handler
    where you are assigning the CssClass you can check whether the row
    being processed is selected or not by comparing e.row.RowIndex with
    the GridView SelectedIndex property. If they match then apply the
    selected row style - you could even vary this according to which group
    the row is in.
     
    Stan, May 12, 2008
    #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. Replies:
    1
    Views:
    660
  2. Daves
    Replies:
    0
    Views:
    757
    Daves
    May 12, 2006
  3. Daves
    Replies:
    0
    Views:
    2,386
    Daves
    May 19, 2006
  4. JB
    Replies:
    2
    Views:
    3,171
    Phil Harvey
    Oct 3, 2009
  5. Peter
    Replies:
    0
    Views:
    587
    Peter
    May 10, 2007
Loading...

Share This Page