Last post Apr 28, 2011 05:56 AM by amitchandnz
Apr 28, 2011 05:31 AM|Dan5|LINK
I have created a dropdownlist just above a gridview that allows users to filter the gridview based on the record type, this allows uses to see only the type of records they are interested in.
What I would like to happen is for the grid to stay filtered even after a page refresh, only when the user has changed the value in the drop downlist should the grid change.
My question is how do I maintain the value of my dropdownlist even after the page has been refreshed, and so keep the gridview displaying the same type of records.
I thought possibly storing the value in a session and rebinding after the page loads..
something like this
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If is postback then
Session("Value") = DropDownList2.SelectedValue.ToString
DropDownList2.SelectedValue = (Session("Value").ToString)
This is not working though...can anyone help..
Apr 28, 2011 05:54 AM|akhhttar|LINK
Yes, you can persist the dropdown selection in Session. Please see following sample code
1. Handle teh Dropdown_SelectedIndex change event and save the Selected value in Session.
<asp:DropDownList ID="ddl1" runat="server" AutoPostBack="true"
protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
Session["DropDownSelection"] = ddl1.SelectedValue;
// Bind the grid according to the selected value
2. On Page_Load, Set the Dropdown SelectedIndex according to the saved value in Session.
protected void Page_Load(object sender, EventArgs e)
if (Session["DropDownSelection"] != null)
ddl1.SelectedIndex = ddl1.Items.IndexOf( ddl1.Items.FindByValue(Convert.ToString(Session["DropDownSelection"]));
//Bind the grid accordng to the dropdown selected value
Hope it helps!
Apr 28, 2011 05:55 AM|karan@dotnet|LINK
If you are using session then you have to store the value of your dropdownlist into session in the selectedindexchanged event of your dropdownlist.
You could also use ajax and wrap your grid inside a update panel
Apr 28, 2011 05:56 AM|shashankgwl|LINK
try this way
in your page load, just write this
public IEnumerable<SomeClass> DataSourceProperty
return Session["Data"] as IEnumerable<SomeClass>
now in dropdown index changed , just update the session with new data.
Apr 28, 2011 05:56 AM|amitchandnz|LINK
Store the value in a session as follows:
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
Session("DropDownList1") = DropDownList1.SelectedIndex
' Bind gridview
Now on the Page_Load event do the following:
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
If Session("DropDownList1") IsNot Nothing Then
DropDownList1.SelectedIndex = CInt(Session("DropDownList1").ToString)
' Bind gridview