During editing in a grid view I want the old values of the particular field in the drop down.
Currently when I enter the edit mode in the gridview i am getting the dropdown as i specified in the list item.
I tried the Selected Value attribute directly but its not working in the grid view. Actually i didn't find it in the Intellisense also.
I found a solution but its working for only odd rows, even rows are not getting showing the same thing.
e.g If i set someones designation as Web Designer when entering the edit mode the dropdown shows Sales which is first in the Data Members.
After adding some code I thought i solved the problem but on closer testing i found the even rows are showing the first value of data member i.e Sales. But for Odd rows its working properly.
The Code:
protected void grdUsers_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton l = (LinkButton)e.Row.FindControl("lnkgrdDelete");
l.Attributes.Add("onclick", "javascript:return confirm('Are You Sure');");
}
if (e.Row.RowState == DataControlRowState.Edit)
{
DropDownList ddl1 = (DropDownList)e.Row.FindControl("ddlgrdDesg");
DropDownList ddl2 = (DropDownList)e.Row.FindControl("ddlgrdUType");
UserBAL user = new UserBAL();
int key = Convert.ToInt32(grdUsers.DataKeys[e.Row.RowIndex].Value.ToString());
string[] data = user.GetUserByID(key);
ddl1.SelectedItem.Text = data[4];
ddl2.SelectedItem.Text = data[5];
}
}
This code works for odd rows but not for even rows. I dont understand something very funny. Its right from my point of view. Also during debugging the even rows never enter the if condition as e.Row.RowState is normal then.