标记
<asp:GridView ID="gridView_Config" runat="server" AutoGenerateColumns="False"
CssClass="gridViewStyle" OnRowDataBound="gridView_Config_RowDataBound" OnSelectedIndexChanged="gridView_Config_SelectedIndexChanged">
<Columns>
<asp:TemplateField ControlStyle-CssClass="ConfigProfileColumn ProfileTextBoxWidth">
<ItemTemplate>
<div>
<asp:TextBox Text='<%# Bind("Type") %>' ID="type" runat="server" ReadOnly="true" CssClass="FieldLabel " ></asp:TextBox>
</div> </ItemTemplate>
</asp:TemplateField> </Columns>
<SelectedRowStyle CssClass="gridViewSelectedRow" />
<HeaderStyle CssClass="gridHeader" />
</asp:GridView>
代码隐藏
protected void gridView_PrintConfig_RowDataBound(object sender, GridViewRowEventArgs e)
{
//check the item being bound is actually a DataRow, if it is,
//wire up the required html events and attach the relevant JavaScripts
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gridView_PrintConfig, "Select$" + e.Row.RowIndex);
}
}
gridViewSelectedRow css类的背景色为蓝色,颜色为白色。但是当选择一行时,模板字段的文本颜色仍然是黑色而不是白色。我该如何解决这个问题?
答案 0 :(得分:0)
您需要在asp:GridView
<asp:CommandField ShowSelectButton="True" Visible="False" />
阅读本文:http://www.codeproject.com/KB/webforms/JavaRowSelect.aspx