[英]Unable to populate drop down list inside gridview
I am binding a dropdownlist i have firstname in the 1st column and lastname as a DDL in the second column` 我正在绑定一个下拉列表,我在第一列中有名字,在第二列中有DDL作为姓氏。
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
DataTable myTable = new DataTable();
DataColumn productIDColumn = new DataColumn("FirstName");
DataColumn productNameColumn = new DataColumn("LastName");
myTable.Columns.Add(productNameColumn);
DataSet ds = new DataSet();
ds = get();
if (e.Row.RowType == DataControlRowType.DataRow)
{
var fname= (e.Row.Cells[0].Text);
var expression = "FirstName "+fname;
DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList1");
DataRow[] rows = ds.Tables[0].Select(expression);
ddl.DataSource = myTable;
ddl.DataTextField = "LastName";
ddl.DataValueField = "LastName";
ddl.DataBind();
}
but the ddl is empty unable to fill the ddl any help on this?? 但是ddl是空的,无法对此填充ddl呢?
Judging from your code, myTable
has no data. 从您的代码来看,
myTable
没有数据。
You are creating myTable
, but you aren't filling it: you are fetching info into the variable ds
, and filtering it into rows
, but you set ddl.DataSource
to myTable
, not to rows
. 您正在创建
myTable
,但没有填充它:您正在将信息获取到变量ds
,并将其过滤到rows
,但是将ddl.DataSource
设置为myTable
,而不是rows
。
Use rows
and you will probably be fine, as long as there is data in rows
. 用
rows
,你可能会被罚款,只要有数据rows
。
ddl.DataSource = rows;
ddl.DataTextField = "LastName";
ddl.DataValueField = "LastName";
ddl.DataBind();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.