Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having a drop down which contaion semester as its values. Its a component of admin panel so i want to maintain the previously selected drop-down value. How can i do this in ASP.Net. I have done this in PHP but i am new to ASP.net so please help me.

Being precise : suppose i have selected Semester-2 then every time I reload the page the default value semester-2 in the drop-down should come.
Posted
Comments
ZurdoDev 23-Apr-13 8:41am    
It is built-in to ASP.Net that after postbacks the value is maintained. If you are talking about refreshing the page then you'll need to store it in the Session and set it on PageLoad.
Zafar Sultan 23-Apr-13 8:42am    
You mean to keep selected value same throughout the application? Unless it is changed manually. Right?
[no name] 23-Apr-13 8:45am    
Yes exactly, i want to use the selected value throught all pages .
smilingsameera 23-Apr-13 8:43am    
Is the dropdown list bound to a database?
[no name] 23-Apr-13 8:46am    
no, i have inserted values statically. Which property should i use to retain session value by default

1 solution

In DropDownlist selectedindexchanged event store the selected value in session as;
C#
Session["DDSelectedValue"] = YourDropDownlistID.SelectedValue;

Now it depends upon you to set the value from session. If the admin panel is user control or on master page etc.

To set the value whenever you bind the dropdownlist use:
C#
YourDropDownlistID.SelectedValue = Session["DDSelectedValue"].ToString();

for further clarification post your code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900