473,467 Members | 2,285 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

10 New Member
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.Items.Add("11111");
ZipDropDown.Items.Add("22222");

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 10494
shweta123
692 Recognized Expert Contributor
Check for isPostback
If Page.IsPostBack = False Then
ZipDropDown.Items.Add("11111");
ZipDropDown.Items.Add("22222");
End if

It should work.


Shweta
Dec 18 '06 #2
radcaesar
759 Recognized Expert Contributor
Use the If (! IsPostBack)

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

Get the value using SelectedValue propeerty.

:)
Dec 18 '06 #3

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

Similar topics

4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
1
by: Dan | last post by:
This is one that has me stumped and I need an expert's input. Any ideas why the values from the second script-generated drop down list isn't recognized by the script to add time values to the...
6
by: Scott Lee | last post by:
I am displaying an ASP.Net generated form in a popup opened with window.showModalDialog. The form contains DropDownList controls. The first ddl is populated via databinding to a datatable, has...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
2
by: Dave A | last post by:
I am stuggling with databinding a drop down list, hooking into the SelectedIndexChanged and attempting to avoid using the viewstate. The drop down list is quite large so I would prefer to avoid...
2
by: jnoody | last post by:
The problem I am having is with the SelectedIndexChanged event not always firing or the SelectedIndex property not being correct when the event does fire. The code is below, but here are some...
6
by: tbrown | last post by:
I have a combobox with items like this: {one,two,three}. The selected index is 0, so "one" appears in the combobox text. When the user drops down the list, and selects "two", for example, I...
4
by: lakepeir | last post by:
Hello, I have combobox with a selectedindexchanged method that seems to be called when starting the application, launching the form with the combobox and making a change in the drop down box of...
1
by: student2008 | last post by:
Sorry about the title its a tricky one. I have a form which allows me to add a question and answers into a mysql database via a combination of, if a certain option is chosen and the reset button...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.