举一个独特的行ID在asp.net gridview的每一行 [英] Give a unique row Id to every row in asp.net gridview
问题描述
我需要给一个唯一的ROWID到asp.net的GridView的每一行。默认行为是它不给任何行的< TR>
生成。如何实现这一目标?
I need to give a unique rowID to every row of a asp.net gridview. Default behavior is it doesn't give any row to the <tr>
generated. How to achieve this?
<tr id="UniqueID" class="orbox" style="color: rgb(51, 51, 51); background-color: AliceBlue; font-size: 11px; cursor: move;" align="center">
<td></td>
</tr>
编辑:见上面code,我要求的HTML标识 ID =UniqueID的
See above code, I am asking for the HTML ID id="UniqueID"
.
推荐答案
将在后面的公众诠释cRowID = 0 code;
在页面类,然后将在GridView中,你获得了使用这个号码,在&LT;%= cRowID ++%&GT;
Place on code behind a public int cRowID = 0;
on the page class, and then place on the GridView where you won to use this ID, the <%=cRowID++%>
.
例如:
<asp:TemplateField HeaderText="ID">
<ItemTemplate ><%=cRowID++%></ItemTemplate>
</asp:TemplateField>
要放置的ID,你可以使用的RowDataBound
抢行并添加为属性的行:
To place the id on the row you can use the RowDataBound
grab the row and add as attribute:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
if (row.RowType == DataControlRowType.DataRow)
{
row.Attributes["id"] = cRowID.ToString();
cRowID++;
}
}
这篇关于举一个独特的行ID在asp.net gridview的每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!