472,119 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

SelectedIndexChanged in drop down - How to get the newly selected value

I am using ASP.Net 2.0 and C# and new to this.

I have programmatically added a zip code drop down into web form inside Page_Load method as:

ZipDropDown is the drop down control on the web page.
I have created a protected void ZipDropDown_SelectedIndexChanged(object sender, EventArgs e) method in my corresponding .cs file for the .aspx file.

protected void ZipDropDown_SelectedIndexChanged(object sender, EventArgs e)
string a = this.ZipDropDown.SelectedItem.Text;
string b = this.ZipDropDown.SelectedItem.Value;

I have set AutoPostBack as true for ZipDropDown control so that the SelectedIndexChanged gets triggered when the user changes zip code from the drop down.

My problem is, in the above code, variables a and b are not getting the correct value when the selection is changed from 11111 to 22222..
The page was populated with the value of the 11111 which is being displayed in the zip code. Then I selected 22222 from the drop down. The ZipDropDown_SelectedIndexChanged got triggered. But the variable a and b still show the value 11111 (old value for drop down), not the newly selected value 22222.

How can I get the newly selected value of 2222 from the dropdown on the server side? How can I also ensure that that new value of 2222 stays displayed in the browser in the drop down?
Dec 15 '06 #1
2 10362
692 Expert 512MB
Check for isPostback
If Page.IsPostBack = False Then
End if

It should work.

Dec 18 '06 #2
759 Expert 512MB
Use the If (! IsPostBack)

Set the ValueMember property of combo to the Member u want.

Get the value using SelectedValue propeerty.

Dec 18 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Dan | last post: by
2 posts views Thread by Yoshitha | last post: by
6 posts views Thread by tbrown | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.