无法在GridView中使用FindControl获得控制权

时间:2014-12-10 18:43:53

标签: c# asp.net

我在行更新时找不到下拉列表: DropDown列表位于 EditTemplate

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    SqlDataSource2.UpdateParameters.Clear();

    string op = "1";
    try
    {
        DropDownList ddl = GridView1.FindControl("ddlprioridade") as DropDownList;
        op = ddl.SelectedValue.ToString();
    }
    catch { }
    ....
}

这个ddl总是 null ,我无法解决这个问题!

1 个答案:

答案 0 :(得分:2)

你试过这个:

var dropDown  = GridView1.Rows[GridView1.EditIndex].FindControl("ddlprioridade") as DropDownList;