您可以在这里快速查找:


 
您的位置: 编程学习 > asp.net教程 > 200510
文章分类

Java技术
2005: 03 04 05 06 07 08
09 10 11 12
2006: 01 02

Asp.net
2005: 07 08 09 10 11 12
2006: 01 02

VB编程
2006: 02

Asp编程
2005: 11 12
2006: 01 02

C++/VC
2005: 10 11 12
2006: 01 02

Delphi
2005: 12
2006: 01 02

其它

 本文章适合所有读者

DataGrid的用法(一)基本用法

freespider

以前工作中曾总结过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

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<Script Language="C#" Runat="Server">
public void Page_Load()
{
 String strSql = "";
 String strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Inetpub\\wwwroot\\DataGrid\\school.mdb";
          
 OleDbConnection objConnection = new OleDbConnection(strConnect);
 objConnection.Open();

 OleDbCommand objCommand = new OleDbCommand();
 objCommand.Connection = objConnection;
 objCommand.CommandType = CommandType.Text;
  
 OleDbDataAdapter sda = new OleDbDataAdapter();
    sda.SelectCommand = objCommand;
    DataSet ds = new DataSet();
   
    strSql = "Select ID, Name, Chinese, Math, English From ScoreSheet";
    objCommand.CommandText = strSql;
    sda.Fill(ds, "ScoreSheet");
   
 DataGrid1.DataSource=ds.Tables["ScoreSheet"].DefaultView;
 DataGrid1.DataBind(); 

    objConnection.Close();
}
</Script>

<asp:DataGrid id="DataGrid1" runat="server" >
</asp:DataGrid>

运行结果:

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

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

敬请关注后面的内容。

漂零 freespider@21cn.com