I would implement the
OnRowDataBound and
OnRowEditing events on the gridview. Inside of your gridview declaration you will have to set these. Which would look like
OnRowDataBound="GridView1_RowDataBound"
. Then for your code behind portion create a fucntion for each of the events like so,
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
}
Inside of each you will have to do different things depending upon your use case. But, inside of the RowEditing event you will need to set
GridView1.EditIndex = e.NewEditIndex;
, so that the gridview contains the corresponding index of the row to edit.
Inside of the RowDataBound insert code like,
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (GridView1.EditIndex == e.Row.RowIndex)
{
DropDownList editGenderValue =
(DropDownList)e.Row.FindControl("gender");
}
}
This is a very short answer to your question that I hope points you in the right direction. If you need more help with implementing this please let me know. Also, there are a few really good articles on code project about how to implement this type of solution in a gridview.
Best of luck and please let me know if you get stuck on anything.