DataGrid的用法(一)基本用法

以前工作中曾总结过DataGrid的用法,可一直被我扔在一边,今日无意中又翻出来,于是想将此文放到csdn,与大家共享,并供大家批判。
此文是DataGrid的入门用法,若你DataGrid很熟悉了,可以不用看了。

目录:
1、DataGrid的基本使用
2、修改DataGrid的Head
3、单击DataGrid,弹出对话框显示此item的详细信息
4、DataGrid的分页显示
5、直接在DataGrid中进行能够编辑
6、如何修改DataGrid中内容的显示
7、如何在DataGrid中新增加一行
8、如何在DataGrid中排序
9、如何在DataGrid中加入checkbox

DataGrid的基本用法: 最好的文档,就是代码。
Class01.aspx

1@ Import Namespace="System.Data" 
1@ Import Namespace="System.Data.OleDb" 
 1<script language="C#" runat="Server">   
 2public void Page_Load()   
 3{   
 4String strSql = "";   
 5String strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\\Inetpub\\\wwwroot\\\DataGrid\\\school.mdb";   
 6  
 7OleDbConnection objConnection = new OleDbConnection(strConnect);   
 8objConnection.Open(); 
 9
10OleDbCommand objCommand = new OleDbCommand();   
11objCommand.Connection = objConnection;   
12objCommand.CommandType = CommandType.Text;   
13  
14OleDbDataAdapter sda = new OleDbDataAdapter();   
15sda.SelectCommand = objCommand;   
16DataSet ds = new DataSet();   
17  
18strSql = "Select ID, Name, Chinese, Math, English From ScoreSheet";   
19objCommand.CommandText = strSql;   
20sda.Fill(ds, "ScoreSheet");   
21  
22DataGrid1.DataSource=ds.Tables["ScoreSheet"].DefaultView;   
23DataGrid1.DataBind(); 
24
25objConnection.Close();   
26}   
27</script>
1<asp:datagrid id="DataGrid1" runat="server">
2</asp:datagrid>

运行结果:

实在很简单吧,为了方便大家,本文的所有代码及其数据库,我提供了下载,大家可以放到本地的环境中运行看看,这样会更直观一些。
http://www.chinacurrents.net/adrift/other/datagrid.rar

第一讲就到此了,基本用法就是基本用法,多一句代码都不写:)

敬请关注后面的内容。

漂零 [email protected]

Published At
Categories with Web编程
Tagged with
comments powered by Disqus