Problems with GridView.CssClass and Selections

J

Jonathan Wood

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.
 
S

Stan

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.

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.
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top