文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>SPGridView的使用--增加自动生成的序列号

SPGridView的使用--增加自动生成的序列号

时间:2010-09-16  来源:bany

  我们在用Gridview,SPGridview进行数据展现和业务处理的时候,难免会需要增加“序号”的栏位,先介绍两种不同的实现方式:

当没有分页时:

1:当栏位是在.ASPX页面手动添加的时候,可使用如下方法:

代码
        <asp:TemplateField HeaderText="&lt;nobr&gt;序号&lt;/nobr&gt;">
                <ItemTemplate>
                       <asp:Label runat="server" ID="lblNo" Text='<%# Container.DataItemIndex   +   1 %>'></asp:Label>
                </ItemTemplate>
        </asp:TemplateField> 

2:当栏位是在后台.CS页面自己生成的栏位的时候,使用如下方法:

代码
    //添加自动生成的序号
    protected void SPGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            int indexID = e.Row.RowIndex + 1;
            e.Row.Cells[0].Text = indexID.ToString();
        } 
    }

当分页时候:

1: 当栏位是在.ASPX页面手动添加的时候,可使用如下方法:

代码
<asp:TemplateField HeaderText="序号" InsertVisible="False">
           <ItemStyle HorizontalAlign="Center" />
           <HeaderStyle HorizontalAlign="Center"/>
            <ItemTemplate>
                   <asp:Label ID="Label2" runat="server" Text='<%# this.GridView1.PageIndex * this.GridView1.PageSize + this.GridView1.Rows.Count + 1%>' />
           </ItemTemplate>
</asp:TemplateField>

2:当栏位是在后台.CS页面自己生成的栏位的时候,使用如下方法:

代码 <asp:BoundField HeaderText="序号" ></asp:BoundField>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)        
{            
    if (e.Row.RowIndex != -1)            
    {                
        int indexID = this.GridView1.PageIndex * this.myGridView.PageSize + e.Row.RowIndex + 1;                
        e.Row.Cells[0].Text = indexID.ToString();            
    }        
}

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载