Problems with GridView.CssClass and Selections

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jonathan Wood

    #1

    Problems with GridView.CssClass and Selections

    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
    SelectedRowStyl e 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


  • Stan

    #2
    Re: Problems with GridView.CssCla ss and Selections

    On 11 May, 17:42, "Jonathan Wood" <jw...@softcirc uits.comwrote:
    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
    SelectedRowStyl e 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.softcircuit s.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.

    Comment

    Working...