欢迎光临!

System.Data.DataTable table = new DataTable();
                System.Data.DataColumn column = new DataColumn();

                column.ColumnName = "序号";
                column.AutoIncrement = true;
                column.AutoIncrementSeed = 1;
                column.AutoIncrementStep = 1;

                table.Columns.Add(column);
                table.Merge(ds.Tables[0]);

                datagridview1.DataSource = table;
                datagridview1.Columns["序号"].DisplayIndex = 0;//调整列顺序
复制过来的,希望对你有帮助,c# 支持 隐式的转换,你也可以用Convert 来转换类型

你也可以使用:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {        if (e.Row.RowIndex >= 0)
        {          
            e.Row.Cells[0].Text = Convert.ToString(e.Row.DataItemIndex + 1);
        }
}

posted on 2019-05-18 15:03  花拉子米  阅读(4902)  评论(0编辑  收藏  举报
版权所有