GridView记录自动序号的两种效果

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {      

 //显示页数量和当前页数
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            int num = GridView1.PageIndex + 1;
            e.Row.Cells[2].Text = "第" + num + "页/共" + GridView1.PageCount + "页";
        }

//第一页

 

//最后一页

////自动附加序号(从第一条到最后一条)
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Text = Convert.ToString(e.Row.DataItemIndex + 1);
        }


//第一页

//最后一页

        ////自动附加序号(单页序号)
        //if (e.Row.RowIndex != -1)
        //{
        //    int id = e.Row.RowIndex + 1;
        //    e.Row.Cells[0].Text = id.ToString();
        //}

}

posted @ 2009-04-01 15:10  寒山潜龙  阅读(433)  评论(1编辑  收藏  举报