GridView添加序号列

在GridView控件第0列添加序号列:

<asp:BoundField HeaderText="序号" >
    <ItemStyle HorizontalAlign="Center" />
    <HeaderStyle HorizontalAlign="Center" Width="30px" />
</asp:BoundField>

为GridView添加OnRowDataBound事件,事件名称为gridViewCPImportPercent_RowDataBound,代码如下:

protected void gridViewCPImportPercent_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();

        ////如果使用了分页控件且希望序号在翻页后不重新计算,使用下面方法
        //int indexID = (AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize + e.Row.RowIndex + 1;
        //e.Row.Cells[0].Text = indexID.ToString();
    }
}
时间: 2024-10-09 11:00:12

GridView添加序号列的相关文章

ASP.NET 为GridView添加序号列,且支持分页连续累计显示

为GridView添加序号列,且支持分页连续累计显示,废话不多说,直接上代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 T

给DataTable添加序号列

如何在datatable中添加一序号列,编号从1依次递增,并且在第一列? /// <summary>        /// 在DataTable中添加一序号列,编号从1依次递增        /// </summary>        /// <param >DataTable</param>        /// <returns></returns>        private DataTable AddSeriNumToDat

AspxGridView添加序号列

using System.Globalization;//CultureInfo需要 protected void AspxGridView_stock_HtmlDataCellPrepared(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableDataCellEventArgs e) { if (e.DataColumn.Caption.Trim() == "序号") { e.Cell.Text = ((e.Vis

RadGridView添加序号列

public class RowNumberColumn : GridViewDataColumn { public override System.Windows.FrameworkElement CreateCellElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem) { TextBlock textBlock = cell.Content as TextBlock; if (textBlo

dataTable添加序号列

使用render( data, type, row, meta )的参数meta 直接新加一个列 columns: [ {data: "id", title: "id", visible: false, searchable: false}, {data: null, tile: "序号", visible: true, searchable: false}, {data: "name", title: "名称&qu

ASP.NET repeater添加序号列的方法

1.<itemtemplate> <tr><td> <%# Container.ItemIndex + 1%> </td></tr> </itemtemplate> 2.<itemtemplate> <tr><td> <%# this.rpResult.Items.Count + 1%> </td></tr> </itemtemplate>

oracle 自动添加序号列 排序

select      HSL.sortno,                    HSL.B,                    HSL.A,                    row_number() over(order by sortno desc) xh               from (select  t.B, t.A ,                            case                              when t.B = '

给mysql查询添加序号列

select *,(@number := @number+1) AS number from (select u.mobile,u.`name`, ROUND((select sum(r.realAmount) from t_recharge r where r.userid=u.id and r.status='1' ),2)rechargeSum, ROUND((select sum(w.realAmount) from t_withdrawal w where w.userid=u.id

mysql中给查询结果添加序号列

生成一个字段(非表中字段)用以记录排序   [类比为oracle数据库中的rownum] MySQL中一个表(表名:stuscore) 字段有:id(主键).stuid(学号).sname(学生姓名).subject(课程名称).score(分数) 列出数学成绩排名 (要求显示字段:排名,姓名 , 课程名称, 分数 , 学号) 用于排名的字段,查询时此处将其用 pm表示  select (@i:[email protected]+1)pm,s.* from stuscore s,(select