Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi,

i have a form when user select value from dropdown it can direct them to another page.but in the next page i want the selected value to be pass to another dropdown.

for instance: user select country;then go straight to next page where there is a dropdown already selected the country value. then only they can do the next process...

note:(listitem in dropdown is same with the 1st)

hope anyone can help me.

thanks.
Posted
Comments
Balakrishnan Dhinakaran 17-Dec-11 5:41am    
my vote 5 for clear description of question

Here is one solution :
Set the AutoPostBack to true in first DropDownList then write in its SelectedIndexChanged event handler :

C#
Session["lastSelectedCountryIndex"] = DropDownList1.SelectedIndex;


In the second page OnLoad event handler write this code :
C#
if (Session["lastSelectedCountryIndex"]!=null)
    DropDownList2.SelectedIndex = Convert.ToInt32((Session["lastSelectedCountryIndex"]).ToString());


There are some other state management options in ASP.NET which can be found here :
http://msdn.microsoft.com/en-us/library/75x4ha6s.aspx[^]

Hope it helps.
 
Share this answer
 
Comments
SharanuKumar 5-Nov-19 0:35am    
Session["lastSelectedCountryIndex"] = DropDownList1.SelectedIndex; is storing the same "lastSelectedCountryIndex" value in the session but not the index 1 in my project...
Pass the selected value to the next page using session.

then on the second page
C#
protected void Page_Load(object sender, EventArgs e)
    {
  ListBox2.Text = <call the session value>
    }
 
Share this answer
 
Their are many ways to pass the values from one page to another page

Some of them are useful to you.
QueryString
Session
 
Share this answer
 
v2
Comments
musiw 18-Dec-11 1:17am    
ok.im using query string.but now the problem is when i have to pass long value it doesnt work it.

i try to pass it to Label first.just to see if it pass the value or not..for example the value is "Signals & Communication Failure"..it just appear Signals the rest are gone.

help me pls.thanks
Sridhar Patnayak 19-Dec-11 1:40am    
You have to send the value of dropdown in the form of String, in the second page you have to convert it in to long value--- it will work
hi,

you may use below code,

C#
public void page_load()
{
  if(!IsPostBack)
  {
      DropDownList ddl = (DropDownList)PreviousPage.FindControl("DropDownList1");
      DropDownList2.SelectedIndex = ddl.SelectedIndex;
  }
}


hope this will help you,

thanks
-amit.
 
Share this answer
 
ok.im using query string.but now the problem is when i have to pass long value it doesnt work it.

i try to pass it to Label first.just to see if it pass the value or not..for example the value is "Signals & Communication Failure"..it just appear Signals the rest are gone.

help me pls.thanks
 
Share this answer
 
Comments
nane aa 18-Dec-11 3:01am    
U put session it is working..
i think this code use for u..

in first page dropdownlist value put in session
in second page means next page

here
yourvalue= session value,
C#
DropDownListID.Items.FindByValue("yourValue").Selected = true;


this second page code in page_load only..
 
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