All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP学习宝典-第一章_[PHP教程]
ASP.NET与Javascript代码结合实现一种常用效果_[Asp.Net教程]
技巧:在ASP.NET页中检测浏览器类型_.net资料_编程技术
Ajax标签导航实例详解-大结局_[AJAX教程]
《SQL,Server,2005技术内幕:T-SQl查询》:常见sql问题归类解答_mssql学习_编程技术
SQL2000中默认sa帐号改名和删除的最安全方法_[SQL Server教程]
SQL Server 2005 存储过程写报表举例_[SQL Server教程]
配置整合Win+Apache+PHP+MySQL+Tcomcat(或Resin)完全手册_[PHP教程]
怎么在ASP.NET,2.0中使用Membership_.net资料_编程技术
ASP.NET Remoting体系结构(四)
Reading number is top 10 pictures
29 the belle stars after bath figure4
Chinese paper-cut grilles art appreciation7
China telecom 114 spokesman MeiYanXu2
非常漂亮的泳装美女
Azusa Yamamoto2
一万二一支的万珂,用得真心肉疼。
关于海盗的研究
Absolutely shocked. National geographic 50 animal photographys2
Rendez-vous Sleep with actress, three days to earn 600000
水晶头骨造型的酒瓶
Download software ranking
Boxer's Top ten classic battle10
金山office2007
豪门浪荡史
Visual C++界面编程技术
C++编程教程第三版
The cock of the Grosvenor LTD handsome
JSP+Ajax Web development typical examples
Unix video tutorial10
matrix3
Boxer Classic video2
归海一刀 published in(发表于) 2014/1/30 1:34:42 Edit(编辑)
将DataGridView中每列分别绑定_[Asp.Net教程]

将DataGridView中每列分别绑定_[Asp.Net教程]

将DataGridView中每列分别绑定_[Asp.Net教程]


1.DataGridView中一列一列的绑定(列名存在集合arrList中,数据存在DataTable)

解释:集合(arrList)中存SQL语句SELECT中的”名字”转换成DataTable的“列名” //通过集合中的名字创建列名
protected DataTable CreateTable(ArrayList arrList, DataReader reader)
// reader可以从ExecuteReader获得
{
// DataTable的名字
DataTable dt = new DataTable("table");
//给DataTable定列名
for (int i = 0; i < arrList.Count; i++)
{
DataColumn dtColumn = new DataColumn();
dtColumn.ColumnName = (string)arrList[i];
dt.Columns.Add(dtColumn);
}
//往DataTable里加行
DataRow dtRow;
while (reader.Read())
{
dtRow = dt.NewRow();
for (int i = 0; i < arrList.Count; i++)
{
try
{
dtRow[(string)arrList[i]] = reader.GetValue(i).ToString();
}
catch
{
dtRow[(string)arrList[i]] = System.DBNull.Value;
}
}
dt.Rows.Add(dtRow);
}
return dt;
}


DataTable m_listViewInfo = CreateTable(集合名,DataReader名);

//将DataTable绑定到DataView中

DataView dvListViewInfo = new DataView(m_listViewInfo);

dataGridView1.Columns.Clear();

//取消dataGridView1按默认方式显示

dataGridView1.AutoGenerateColumns = false;

//绑定DataView到dataGridView上

dataGridView1.DataSource = dvListViewInfo;

DataGridViewTextBoxColumn dtcTimeStamp = new DataGridViewTextBoxColumn();

dtcTimeStamp.DataPropertyName = "TIMESTAMP";//SQL语句得到的列名,可从集合中获得

dtcTimeStamp.HeaderText = "日期";//列头显示的汉字

dtcTimeStamp.Width = 110;

dataGridView1.Columns.Add(dtcTimeStamp);//最后一定要添加进去




添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.