Sorry for the late response. Been away for a while. Odd that noone picked this one up. For DDL, I have this situation regularly. Actualy, I save and restore DDL selection even on regular DDLs. That way I can work all over my website and when I get back to the page, I get the old selection there. Only limitation to how I do it is that the DDL has the same items in it every time.
Saving is done in the SelectedIndexChanged of the DDL:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Session["DropDownList1_SelectedIndex"] = DropDownList1.SelectedIndex;
}
Restoring what was saved in DataBound:
protected void DropDownList1_DataBound(object sender, EventArgs e)
{
if(Session["DropDownList1_SelectedIndex"] != null)
{
DropDownList1.SelectedIndex = (int)Session["DropDownList1_SelectedIndex"];
}
}
This is for a single one. To save/restore per line of the GridView, the RowIndex of the GridViewRow the DDL is in could be added to the name of the session index. Or the KeyValue of the GridViewRow. For saving that would look somewhat like this:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Session[String.Format("DropDownList1_SelectedIndex_{0}", ((GridViewRow)((Control)sender).NamingContainer).RowIndex)]
= DropDownList1.SelectedIndex;
}
(Haven't tested it, so there may be a few bumps to hammer out.)
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you.
This can be beneficial to other community members reading the thread.
When all you've got is a Hammer,
Every Problem looks like a Nail.
Michael Swain.