【发布时间】:2017-03-07 15:36:08
【问题描述】:
我有一个带有标签控件的列,它将计数保持在嵌套在中继器中的 Gridview 中。如果显示 3 个 Gridview,每个 5 行,如何在 Gridview 的 RowDataBound 事件中继续编号?目前,当我使用
时,Gridview 会重新开始(e.Row.FindControl("lblCount") as Label).Text = (e.Row.RowIndex +1).ToString();
目前的结果:
Gridview1
1
2
3
4
5
Gridview2
1
2
3
4
5
Gridview3
1
2
3
4
5
期望的结果:
Gridview1
1
2
3
4
5
Gridview2
6
7
8
9
10
Gridview3
11
12
13
14
15
.aspx 页面
<asp:Repeater ID="rptGridViews" OnItemDataBound="rptGridViews_ItemDataBound" runat="server">
<ItemTemplate>
<asp:GridView ID="gvProposals" OnRowDataBound="gvProposals_RowDataBound" runat="server">
<Columns>
<asp:TemplateField HeaderText="Count">
<ItemTemplate>
<asp:Label ID="lblCount" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:Gridview>
</ItemTemplate>
</asp:Repeater>
.aspx.cs
protected void gvProposals_RowDataBound(object sender, GridViewRowEventArgs e){
if(e.Row.RowType == DataControlRowType.DataRow)
{
(e.Row.FindControl("lblCount") as Label).Text = (e.Row.RowIndex+1).ToString();
}
}
【问题讨论】:
标签: c# asp.net gridview repeater