我正在绑定一个下拉列表,我在第一列中有名字,在第二列中有姓氏作为 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();
}
但是 ddl 是空的,无法填充 ddl 对此有任何帮助吗?