J
Jonathan Wood
I'm having problems with the following code, which is an event handler for a
GridView control:
protected void grdWorkout_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow) // Not header, footer,
etc.
{
System.Data.DataRowView drv = (System.Data.DataRowView)e.Row.DataItem;
if (drv != null)
{
if ((e.Row.RowState & DataControlRowState.Selected) != 0)
e.Row.CssClass = "gridsel";
else if (drv.Row.ItemArray[5].ToString() == "Arm")
e.Row.CssClass = "gridalt";
}
}
}
When the page comes up, it looks fine. But if I select a row in the
GridView, it only appears selected if the 5th column is not equal to "Arm".
Put another way, if I set e.Row.CssClass = "gridalt", it appears that row
will always use that style whether it is selected or not.
So I tried putting similar code in the RowCreated event handler. That also
looks fine when the page comes up. But then when I select a row, it appears
selected, but NONE of the rows then use the gridalt CSS class. The reason is
that drv is null except for when the page is first loaded.
Can anyone make some suggestions? I need to control the row styles because
my alternating style will not occur on every other row. But I can't find any
way to make this compatible with selecting rows.
Thanks.
GridView control:
protected void grdWorkout_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow) // Not header, footer,
etc.
{
System.Data.DataRowView drv = (System.Data.DataRowView)e.Row.DataItem;
if (drv != null)
{
if ((e.Row.RowState & DataControlRowState.Selected) != 0)
e.Row.CssClass = "gridsel";
else if (drv.Row.ItemArray[5].ToString() == "Arm")
e.Row.CssClass = "gridalt";
}
}
}
When the page comes up, it looks fine. But if I select a row in the
GridView, it only appears selected if the 5th column is not equal to "Arm".
Put another way, if I set e.Row.CssClass = "gridalt", it appears that row
will always use that style whether it is selected or not.
So I tried putting similar code in the RowCreated event handler. That also
looks fine when the page comes up. But then when I select a row, it appears
selected, but NONE of the rows then use the gridalt CSS class. The reason is
that drv is null except for when the page is first loaded.
Can anyone make some suggestions? I need to control the row styles because
my alternating style will not occur on every other row. But I can't find any
way to make this compatible with selecting rows.
Thanks.