• ASP.NET DridView 显示行号


    方法一

    aspx

    GridView 添加 

    OnDataBound="GridView1_DataBound"

    <asp:TemplateField ItemStyle-Width="50px" ItemStyle-HorizontalAlign="Center">
                        <HeaderTemplate>
                            序号</HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
     aspx.cs

    加入

    protected void GridView1_DataBound(object sender, EventArgs e)
            {
                int num = GridView1.Rows.Count;
                for (int i = 0; i < num; i++)
                {
                    Label lbl = (Label)GridView1.Rows[i].FindControl("Label1");
                    lbl.Text = (i+1).ToString();
                }
            }

    方法二(简单):

    <asp:TemplateField ItemStyle-Width="50px" ItemStyle-HorizontalAlign="Center">
                        <HeaderTemplate>
                            序号</HeaderTemplate>
                        <ItemTemplate>
                            <%#Container.DataItemIndex+1 %></ItemTemplate>
     </asp:TemplateField>
     OK

  • 相关阅读:
    HDU 4644 BWT (KMP)
    常数的值类型问题
    HDU 1395 2^x mod n = 1 (欧拉函数)
    HDU 5384 Danganronpa(AC自动机)
    9.自己实现linux中的tree
    8.底层文件库
    7.标准文件库
    7.gcc的使用
    5.文件I/O
    4.vim操作
  • 原文地址:https://www.cnblogs.com/hakuci/p/2454835.html
Copyright © 2020-2023  润新知