ASP.NET中的GridView控件如何读取行号?

来源:百度知道 编辑:UC知道 时间:2024/06/28 06:16:53
如题,我要用GridView控件来显示数据,怎么按顺序显示数据是第几条,比如说用来文章评论的一楼二楼...
<asp:Label ID="Label1" runat="server" Text="<%#Container.DataItemIndex+1%>"></asp:Label>
这个可以,但我想反过来又怎样做啊?...3 2 1

<asp:TemplateField HeaderText="楼数">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="<%#Container.DataItemIndex+1%>"></asp:Label>
</ItemTemplate>
</asp:TemplateField>

倒序"
<%# (this.Pager.CurrentPageIndex - 1) * this.Pager.PageSize + this.Rows.Count - Container.DataItemIndex %>

添加一个模板列放一个Lable
在RowDataBound事件里面可以这样获得GridView的索引

e.Row.RowIndex;
然后找到行中的那个Lable
if (e.Row.RowType == DataControlRowType.DataRow)
{

Label Lb_Del = (Label)gr.FindControl("Lb_Del"); //找到绑定到该行的Label
Lb_Del.Text="第"+e.Row.RowIndex+1+"楼";
如果不做处理索引是从0行开始,所以每次要加1.

要根据索引来确定是中文第几楼,那就是另外的处理了.

学习...

e.Row.RowIndex;