CSDN博客

img bccu

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

发表于2004/10/14 17:24:00  884人阅读


动态的添加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;
 }

阅读全文
0 0

相关文章推荐

img
取 消
img