painfully ignorant but frustrating

D

dan m

I HAVE looked around but cant figure out the stupid mistake I'm
making. I am POSTing a form and in the CodeBehind function for the
submit i am simply building a SQL statement, however, I cant seem to
retrieve the correct (newly selected) values for the dropdownlist
controls. I'm sorry, i know this is elementary but I just cant see my
error - anyone give me the lowdown?!

SQL string below: (Im trying both the selected item & index but both
give the original value when first rendered)...

INSERT INTO Team " +
"(TeamName, Email, fkManufacturerId," +
"fkDriver1Id, fkDriver2Id, fkDriver3Id," +
"fkTyreId,Paid) " +
" VALUES " +
"('" + txtTeamName.Text + "'," +
"'" + txtUserId.Text + "'," +
ddlManufacturer.SelectedIndex + "," +
ddlDriver1.SelectedItem.Value + "," +
ddlDriver2.SelectedItem.Value + "," +
ddlDriver3.SelectedItem.Text + "," +
ddlTyre.SelectedItem.Value + "," +
"False);";

cheers, dan
 
C

Corey O'Mara

Perhaps your dropdownlists are being re-initialized on page_load and
therefore resetting the .SelectedItem property? Remember to populate your
dropdowns inside a "If Not Page.IsPostBack" statement. If this is not the
case, page_load will fire before your event handler and cause the dropdowns
to repopulate and your SelectedItem won't be set properly.

Corey O'Mara
MCSD.NET, MCT
 
D

dan m

THANKYOU Corey! - Perfect answer and as i said, a real simple
(obvious) mistake which i just couldnt see!

Kind regards, dan
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top