DataGrid的用法(一)基本用法
2024-07-21 02:23:26
供稿:網友
本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。以前工作中曾總結過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
第一講就到此了,基本用法就是基本用法,多一句代碼都不寫:)
敬請關注后面的內容。
漂零 [email protected]