Dynamically Change The Class Of A Div Nested In A Gridview Item Template From Code Behind C#
I need to change the class of a div nested inside a gridview item template, i have given the runat='server' tag and an id for the div. How can we change the class of that particula
Solution 1:
ASPX
<asp:GridView ID="gv" runat="server" OnRowDataBound="gv_OnRowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<div id="yourDiv" runat="server"></div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code-behind
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow) {
HtmlGenericControl div = (HtmlGenericControl)e.Row.FindControl("yourDiv");
div.Attributes.Add("class", "ClassYouWantToAdd");
}
}
Post a Comment for "Dynamically Change The Class Of A Div Nested In A Gridview Item Template From Code Behind C#"