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?
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
}
}
}
When you switch to the edit mode, you need to rebind the grid for this to take effect.
So, you can use the 'RowDataBound' event.
void MyGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow
&& e.Row.RowIndex == MyGridView.EditIndex)
{
DropDownList d1 = e.Row.FindControl("d1") as DropDownList;
if(d1 == null) return;
//Now you have the drop down. Use it as you wish.
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With