我有一个DropDownlist
,GridView
只有在单击编辑时才应该可见。我已经绑定了DropDownList
后面的代码。当我单击编辑时,该单元格的标签值应自动在DropDownList
.
我试过的代码是:
protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
SqlCommand cmd = new SqlCommand("SELECT Location_Name FROM Location_Table");
DropDownList bind_drop = (e.Row.FindControl("DropList") as DropDownList);
bind_drop.DataSource = this.ExecuteQuery(cmd, "SELECT");
bind_drop.DataTextField = "Location_Name";
bind_drop.DataValueField = "Location_Name";
bind_drop.DataBind();
string Loc_type = (e.Row.FindControl("id2") as Label).Text.Trim();
bind_drop.Items.FindByValue(Loc_type).Selected = true;
}
}
当我运行代码时,它给出了一个异常错误对象引用未在上述代码的最后一行设置。查不出什么问题。请帮助