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

推荐订阅源

博客园_首页
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Engineering at Meta
Engineering at Meta
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
M
MIT News - Artificial intelligence
IT之家
IT之家
博客园 - 【当耐特】
U
Unit 42
云风的 BLOG
云风的 BLOG
L
LangChain Blog
小众软件
小众软件
Microsoft Security Blog
Microsoft Security Blog
B
Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
宝玉的分享
宝玉的分享
N
Netflix TechBlog - Medium

博客园 - Emmet.C

[求助]关于Vsiual Studio.NET 2005中Error List种错误的定位问题 【求助】关于asp.net中的'Thread was being aborted'异常 安装Tomcat 5.0.28备注 如何在运行时定制DataGrid的显示风格? asp.net中如何回车触发指定按钮的事件 Jbuilder2005安装备注 使用Singleton改善ASP.NET性能备注 Infragistics.WebUI.UltraWebTab.v4.3使用备注 WinForm界面模式 如何定制WebCarlendar类型控件的星期格式 .NET在Debug模式下的编译错误 Infragistics UltraWebTab的奇怪问题 架构设计备注(用户以及操作权限管理) 关于通过手机收发短信的相关资源 Read CPU ID(from CSDN) 可用性相关的资料站点 万网企业邮箱开始提供垃圾邮件过滤功能了 为何使用表格排版是不明智的? 申请了GMail
DataGrid动态绑定
Emmet.C · 2004-12-10 · via 博客园 - Emmet.C

今天需要在运行时动态绑定DataSet到DataGrid的特定列。网上找了一下,看到了一个例子,我觉得很简单,但是可以在将来为我自己作为提示。

给hongfly的动态绑定列简单代码
没给写带模版列的,比较多。所以写了个基本的。这里只写了帮定一列。
//关闭自动生成列
DataGrid1.AutoGenerateColumns = false ;
//建立dataset
DataSet ds = DB.GetDataSet();
//绑定一列
BoundColumn col = new BoundColumn();
//指定页眉
col.HeaderText = "页眉" ;
//指定字段名 
col.DataField = "字段名" ;
//只读
col.ReadOnly = true ;
//指定列隐藏(为ID时用到)
col.Visibel = true ;
DataGrid.Columns.Add(col) ;
DataGrid.DataSource = ds.Tables[0];
DataGrid.DataBind() ;