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

推荐订阅源

T
Tor Project blog
B
Blog RSS Feed
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
H
Hackread – Cybersecurity News, Data Breaches, AI and More
罗磊的独立博客
GbyAI
GbyAI
N
Netflix TechBlog - Medium
博客园 - 司徒正美
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
宝玉的分享
宝玉的分享
W
WeLiveSecurity
Stack Overflow Blog
Stack Overflow Blog
Y
Y Combinator Blog
SecWiki News
SecWiki News
V
Vulnerabilities – Threatpost
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Register - Security
The Register - Security
Cisco Talos Blog
Cisco Talos Blog
Martin Fowler
Martin Fowler
A
About on SuperTechFans
S
Security @ Cisco Blogs
T
Tenable Blog
C
Check Point Blog
N
News and Events Feed by Topic
S
SegmentFault 最新的问题
The GitHub Blog
The GitHub Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Attack and Defense Labs
Attack and Defense Labs
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cisco Blogs
P
Palo Alto Networks Blog
V
V2EX
博客园 - 聂微东
Project Zero
Project Zero
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Docker
N
News | PayPal Newsroom
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
小众软件
小众软件
Application and Cybersecurity Blog
Application and Cybersecurity Blog
人人都是产品经理
人人都是产品经理
V2EX - 技术
V2EX - 技术
I
Intezer
L
LINUX DO - 最新话题

博客园 - 花拉子米

第一章、安装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);
        }
}