Eve
Eve

Reputation: 212

Grid view SelectedRowStyle does not apply to Template Fields

Markup

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

Code-Behind

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); 
    } 
}

The gridViewSelectedRow css class has background color blue and color as white. but when a row is selected the text color of the template field still remains black instead of white. how do i solve this?

Upvotes: 0

Views: 1200

Answers (1)

codeandcloud
codeandcloud

Reputation: 55248

You are required to add Select Button in your asp:GridView

<asp:CommandField ShowSelectButton="True" Visible="False" />

Read this: http://www.codeproject.com/KB/webforms/JavaRowSelect.aspx

Upvotes: 1

Related Questions