国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

使用自定義的數(shù)據(jù)源進行DataGrid控件的數(shù)據(jù)綁定

2024-07-21 02:23:31
字體:
來源:轉載
供稿:網(wǎng)友
注冊會員,創(chuàng)建你的web開發(fā)資料庫,自定義的集合類
/// <summary>
/// collection 的摘要說明。
/// </summary>
public class collection : system.collections.collectionbase
{
public collection()
{
for(int i = 0;i < 10;i++)
{
base.innerlist.add(new element(i,string.format("a[{0}]",i)));
}
}
}

集合元素類
public class element
{
private string name;
public string valuename
{
get{return name;}
}
private int valu;
public int value
{
get{return valu;}
}
public element(int val,string nam)
{
name = nam;
valu = val;
}
}

aspx的后置代碼
/// <summary>
/// webform1 的摘要說明。
/// </summary>
public class webform1 : system.web.ui.page
{
protected system.web.ui.webcontrols.datagrid datagrid1;

private void page_load(object sender, system.eventargs e)
{
datagrid1.datasource = new collection();
datagrid1.databind();
}

#region web 窗體設計器生成的代碼
override protected void oninit(eventargs e)
{
//
// codegen: 該調(diào)用是 asp.net web 窗體設計器所必需的。
//
initializecomponent();
base.oninit(e);
}

/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void initializecomponent()
{
this.load += new system.eventhandler(this.page_load);

}
#endregion
}

aspx頁的html代碼
<body ms_positioning="flowlayout">
<form id="form1" method="post" runat="server">
<asp:datagrid id="datagrid1" runat="server" autogeneratecolumns="false" width="224px">
<columns>
<asp:templatecolumn headertext="名稱">
<itemtemplate>
<asp:label runat="server" text='<%# databinder.eval(container, "dataitem.valuename") %>'>
</asp:label>
</itemtemplate>
<edititemtemplate>
<asp:textbox runat="server" text='<%# databinder.eval(container, "dataitem") %>'>
</asp:textbox>
</edititemtemplate>
</asp:templatecolumn>
<asp:templatecolumn headertext="數(shù)字">
<itemtemplate>
<asp:label runat="server" text='<%# databinder.eval(container, "dataitem.value") %>'>
</asp:label>
</itemtemplate>
<edititemtemplate>
<asp:textbox runat="server" text='<%# databinder.eval(container, "dataitem") %>'>
</asp:textbox>
</edititemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
</form>
</body>
</html>




發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 孝感市| 玛多县| 吉水县| 营口市| 龙泉市| 荃湾区| 临猗县| 德安县| 治县。| 崇信县| 温州市| 嵩明县| 科技| 平潭县| 西宁市| 双桥区| 庆阳市| 加查县| 板桥市| 铜陵市| 武夷山市| 陆川县| 深泽县| 兰溪市| 南通市| 阜新市| 定安县| 克山县| 广德县| 土默特左旗| 项城市| 高雄县| 齐齐哈尔市| 宁城县| 聊城市| 营山县| 驻马店市| 木兰县| 永安市| 建宁县| 平舆县|