Application of drop-down box in DataGrid

xiaoxiao2021-03-06  87

Select

Type


DataSource = '<% # getatypes (databinder.eval ("name"). TSTRING ())%>'

DataBinder.eval ("Name") Name is binding to the column name in the data source table of this DataGrid If the drop-down box is to be bind to one of the columns, you can write directly to DataSource = '<% # databinder. Eval (Container.DataItem, "YourColumnName")%>

And if you want to determine the bind to the corresponding table according to the value of a column, you need to write a method (Getatypes () in my example is your own defined) and then call it. The return value of this method is a DataView

code show as below:

Public DataView getatypes (String Type) {// According to your needs, modify the corresponding code string Tablename = Sqllibrary.gettablename (Type); string sqlstr = "SELECT '-1' AS ID, 'All' AS Name from" TableName "Union Select * from" TableName; DS = conn.getdatanet (SQLSTR); DV = DS.TABLES [0] .defaultView;

//dv.rowfilter = "id =" ID "OR ID = 0"; return DV;}

DataTextField = "name" DataValuefield = "ID"

The name and id here are column names that are bound to the table of this drop-down box (note is not binding to the column name in the DataGrid table)

The value displayed in the drop-down box is the value of DataTextField binding and each value has an index value DataValuefield.

You can get values ​​from the drop-down box from your own needs or the corresponding index value.

转载请注明原文地址:https://www.9cbs.com/read-122302.html

New Post(0)