可能重复:
在网格视图中填充下拉列表
我有一个下拉列表,我在 gridview 中填充它。在第一列中我有 Firstname,在第二列中我有一个 DDL,我想加载与 firstname 关联的 lastname 我该如何实现?
Protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
con.Open();
var ddl = (DropDownList)e.Row.FindControl("DropDownList1");
//int CountryId = Convert.ToInt32(e.Row.Cells[0].Text);
SqlCommand cmd = new SqlCommand("select FirstName,LastName from Profile_Master" , con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddl.DataSource = ds;
ddl.DataTextField = "LastName";
ddl.DataValueField = "FirstName";
ddl.DataBind();
}
}