在网格视图中绑定下拉列表 [英] Binding Drop Down List in the grid view
本文介绍了在网格视图中绑定下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何将记录绑定到gridviews项目模板字段中的下拉列表。
如果我在运行时单击编辑按钮然后特定下拉列表应该得到特定下拉列表填充数据。
如何实现这个目标。
任何想法??
Guys i want to know about how to bind a records to the dropdown list which is in the gridviews item template field.
if i click edit button at runtime then that paricular rows particular dropdown should get filled with the data.
How to achieve this.
any idea??
推荐答案
http://www.aspdotnet-suresh.com/2012/05/bind -data-to-dropdownlist-in-gridview.html [ ^ ]
使用gridview数据绑定事件...请参阅以下代码
use gridview databound event for that... refer following code
protected void test_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = (DropDownList)e.Row.FindControl("yourDropDownListID");
ddl.DataSource = //assing your datasorce here to bind to your dropdown list
ddl.DataBind();
}
}
嗨Sachin,
网格行绑定事件
Hi Sachin,
on the grid row bound event
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Control ctrl = e.Row.FindControl("ddlName");
if (ctrl != null)
{
DropDownList ddl = (DropDownList)ctrl;
DataTable dt =GetData(); // get your data either in list or datatable
ddl.DataSource = dt ; // Specify here either list or datatable
ddl.DataTextField = "Name"; // specify here display Member
ddl.DataValueField = "Id"; // specify here value member
ddl.DataBind();
}
}
这篇关于在网格视图中绑定下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文