DataGrid的用法(一)基本用法

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航