I've got GridView with selection enabled. Some columns in GridView have CssClass set, setting their background color. Also, there is SelectedRowStyle defined in GridView.
Problem is, after row is selected, it's background color is changed as defined in SelectedRowStyle, except columns with own CssClass set. Their background color remains unchanged, and I would like all columns in selected row to have same color (defined in SelectedRowStyle).
I'm using VS2008 and .NET Framework 3.5.
GridView:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
OnRowDataBound="GridView1_RowDataBound" AllowPaging="True" PageSize="50" CssClass="gv"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnPageIndexChanged="GridView1_PageIndexChanged"
DataKeyNames="Name" RowStyle-Wrap="False">
<RowStyle Font-Names="Calibri" Font-Size="Small" BackColor="White" ForeColor="#333333" />
<SelectedRowStyle BackColor="#336699" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
<asp:BoundField DataField="Qty" HeaderText="Qty" SortExpression="Qty" />
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
<asp:BoundField DataField="Level" HeaderText="Level" SortExpression="Level" ItemStyle-CssClass="bglightred" />
<asp:BoundField DataField="Log" HeaderText="Log" SortExpression="Log" ItemStyle-CssClass="bglightred" />
</Columns>
CSS:
.gv td.bglightred
{
background-color: #FF8080;
}
.gv tr:hover td
{
background-color: #CCCCCC;cursor: default;
}
Code:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(GridView1, "Select$" + e.Row.RowIndex.ToString()));
}
}