Hi Rizwan, Here is the solution:-
1. Firstly, Set autopostback of dropdownlist to
"False"
2. With the use of RowCommand Event of the Grid View , Get the value of the Edited Label into the ViewState, As below:-
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
GridViewRow gvRow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
Label lbl = (Label)gvRow.FindControl("Label1");
ViewState["LabelValue"] = lbl.Text;
}
}
3. Finally, Use viewstate and Handle your RowDataBound Event as below :-
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && GridView1.EditIndex == e.Row.RowIndex)
{
DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList1");
ddl.SelectedValue = ddl.Items.FindByText(Convert.ToString(ViewState["LabelValue"])).Value;
}
}
4. Your Job Is done !!!
~Thanks