惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
美团技术团队
N
Netflix TechBlog - Medium
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
F
Fortinet All Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
MyScale Blog
MyScale Blog
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
The Cloudflare Blog
量子位
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
DataBreaches.Net
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - 花拉子米

第一章、安装odoo的开发环境 [转] sp_getAppLock使用[转] sqlserver 索引优化 CPU占用过高 执行分析 服务器检查[转] python操作excel[转] 电子商城项目开发(后台功能模块开发) 【转】 电子商城项目开发(前台功能模块开发)【转】 sql server 全角与半角字符转换 sp_Msforeachtable与sp_Msforeachdb详解 sql server 查看索引碎片大小,并定期重建索引 Git安装 Git使用 sql 索引【转】 SVN安装使用【转】 asp.net mvc 使用Ajax调用Action 返回数据【转】 MVC与ajax【转】 sql server block如何查询并kill 软件概要设计文档【转】 软件详细设计文档【转】 软件需求规格说明书【转】
c# 如何给 dataGridView里添加一个自增长列(列名为序号)
花拉子米 · 2019-05-18 · via 博客园 - 花拉子米

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);
        }
}