Trouble getting selected Index from dropdownlist bound to datareader.

B

Billy Jacobs

Fairly Complicated Problem:
1. I have a C# web application.
2. I have a web form with 3 drop down list controls and
other text box controls for updating user information.
3. There is a submit button.
4. On the page_load of the webform I databind three
dropdownlist controls to a different datareaders.

Results:
1. When I run the page displays correctly with the
dropdown lists populated with the items from the DB.
2. I can make different selections in the dropdownlists.
3. When I click the submit button is where I have
problems.

Where I am at:
1. I can get the changed values for all of the textboxes.
2. I cannot get the values I chose in the dropdownlists.
3. The selectedIndexes of the dropdownlists remain at
whichever value I initialize them to.
4. I added an event handler to capture the SelectedIndex
Change event to see its value. This event fires but the
selectedIndex does not change. Also this event fires
before the submit.Click event handler fires.

Help

Billy Jacobs



When I click submit
3. There is no code behind page. All programmatic
functions are in a Control which it References.
 
T

Tian Min Huang

Hi Billy,

Thanks for your post. As I understand, the problem you are facing is that
you can not get the newly selected item in te dropdownlist in server code.
Please correct me if there is misunderstanding. Based on my experience, I
believe that the dropdownlist control does not post back the data to
server. I'd like you check the following issue:

1. Make sure the "AutoPostBack" property of the dropdownlist is set to True.
2. Do not bind the controls in the Page_Load method if it is postback.
Please refer to the followign code:

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
//databind three dropdownlist controls here
}
}

Please let me know the result.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
B

Billy Jacobs

You are correct about my problem and the solution.
However I don't need to set autopostback = true. Only
need to NOT databind if IsPostBack.

Billy Jacobs
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top