C# – ASP.NET GridView EditTemplate and find control

asp.netcgridview

In the GridView we are using an edit button. Once the edit button is clicked Controls in the edit template will display in the same row with update button. That row has two dropdownlist controls.

Process flow:

controls:d1 and d2

d1 is using sqldatasource for item display : working fine.

d2 is using codebehind code to load the item based on the selected value in the d1 : Not working

How to find the control in the edit template to display item value for d2?

Best Answer

I got the answer.

protected void GridView1_PreRender(object sender, EventArgs e)
 {
  if (this.GridView1.EditIndex != -1)
   {
     Button b = GridView1.Rows[GridView1.EditIndex].FindControl("Button1") as Button;
     if (b != null)
      {
      //do something
      }
   }
 }
Related Topic