我在Gridview中有一個下拉列表,我必須顯示與每個id相關的記錄。並且該ID包含超過10條記錄,所以如何顯示它們?在GridView中填充下拉列表
protected void GridView1_RowDataBound(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 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.DataBind();
}
}
你是否嘗試將'ddl.DataValueField'分配給其他一些像ID一樣的列? – Ahmad
沒有我分配這樣的,但有什麼用? –