您的位置:首页 > 其它

webgrid的使用:(二)、动态的添加webcombo到webgrid上的操作

2004-10-14 17:24 483 查看
动态的添加webcombo到webgrid上的操作:

1、在页面中用代码添加一个webcombo.

ISNet.WebUI.WebCombo.WebCombo wc =new ISNet.WebUI.WebCombo.WebCombo("wcSupplier");
wc.InitializeDataSource += new ISNet.WebUI.WebCombo.DataSourceEventHandler(wcSupplier_InitData);
wc.DataTextField = "ContactName";
wc.DataValueField = "SupplierID";
Page.FindControl("form1").Controls.Add(wc);

2、给webgrid指定的列添加为webcombo

private void WebGrid1_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
{
WebGrid1.RootTable.Columns.GetNamedItem("SupplierID").EditType = EditType.WebComboNET;
WebGrid1.RootTable.Columns.GetNamedItem("SupplierID").WebComboID = "wcSupplier";

WebValueList vl = WebGrid1.RootTable.Columns.GetNamedItem("SupplierID").ValueList;

if (!vl.IsDataCached())
vl.DataSource = GetSupplierList();

vl.DataTextField = "ContactName";
vl.DataValueField = "SupplierID";
}

3、为webcombo指定资源

private void wcSupplier_InitData(object sender, ISNet.WebUI.WebCombo.DataSourceEventArgs e)
{
e.DataSource = GetSupplierList();
}

DataTable GetSupplierList()
{
DataTable dt = new DataTable("Suppliers");
OleDbDataAdapter da = new OleDbDataAdapter("select * from suppliers", oleDbConnection1);
da.Fill(dt);

return dt;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐