动态更改嵌套在gridview项模板中的div类, [英] Dynamically change the class of a div nested in a gridview item template from code behind c#
本文介绍了动态更改嵌套在gridview项模板中的div类,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要更改嵌套在gridview项目模板中的div类,我给了runat =server标签和div的id。我们如何才能根据每一行的条件来改变gridview数据绑定中特定div的类。
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 particular div upon gridview databind based on each row conditions.
推荐答案
ASPX
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
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");
}
}
这篇关于动态更改嵌套在gridview项模板中的div类,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文