0

I can't find the dropdown list on row updating: DropDown list is in 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 { }
    ....
}

This ddl is allways null and i can't solve this!

Masoud Mohammadi
  • 1,721
  • 1
  • 23
  • 41
Severiano
  • 1,083
  • 3
  • 25
  • 54
  • Possible duplicate: http://stackoverflow.com/questions/14584175/how-to-find-control-in-edit-item-template – Joce Pedno Dec 10 '14 at 18:48
  • no, its different! :( – Severiano Dec 10 '14 at 18:49
  • A couple of nit picks: 1) A `try` with an empty `catch` should only be used for debugging code. It should never make it to production; 2) The `SelectedValue` property of a DropDownList object is already a string. No need to call `ToString()` here. Also I agree with @Severiano about this not being a duplicate question. – Greg Burghardt Dec 10 '14 at 19:00

1 Answers1

2

Have you tried this:

var dropDown  = GridView1.Rows[GridView1.EditIndex].FindControl("ddlprioridade") as DropDownList;
Joce Pedno
  • 334
  • 1
  • 7