如何将gridview中的下拉列表与每行的不同数据绑定
问题描述:
我有一个GridView,其中我有像MachineCode,MachineName和OperationName这样的列,其中OperationName是DropdownList。
用户想要为该特定机器选择操作。对于每台机器的操作都可以不同。我想用不同的数据源绑定每一行中的每个Dropdownlist。如何在c#中执行此操作?
I have a GridView in which I have columns like MachineCode, MachineName and OperationName were OperationName is DropdownList.
User want to select Operations for that perticular machine. For every machines operations can be different. I want to bind every Dropdownlist in each row with diferent datasource. how to do this in c#?
答
试试这个
http://www.dotnetcurry.com/showarticle.aspx?ID=221 [ ^ ]
希望这有帮助
Try this
http://www.dotnetcurry.com/showarticle.aspx?ID=221[^]
Hope this helps
您可以将数据源绑定到下拉列表在GridView的RowDataBound事件中
You can bind the datasource to dropdownlist in GridView's RowDataBound Event
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList1");
ddl.DataSource = your_data_set;
ddl.DataBind();
}