Drop down list indexing problem

A

anony

Hi,

I'm populating a drop down list asp.net control with the following code:

cmdSqlCommand.CommandText = "SELECT SUBMITTEDBYID, FIRSTNAME + ' ' +
LASTNAME AS FIRSTLAST FROM xxx ORDER BY FIRSTNAME"

dtrSqlDataReader = cmdSqlCommand.ExecuteReader()

dropSubmittedBy.DataSource = dtrSqlDataReader
dropSubmittedBy.DataTextField = "FIRSTLAST"
dropSubmittedBy.DataValueField = "SUBMITTEDBYID"
dropSubmittedBy.DataBind

Example table data:

SUBMITTEDBY ID FIRSTNAME LASTNAME
0 Will Smith
1 Tim Jones
2 Mark Rogers

If I run the SQL statement in Query Analyzer, the results are as expected.

2 Mark Rogers
1 Tim Jones
0 Will Smith

But through the web application, the DataValueFields get screwed up. They
end up being numbered sequentially by the alphabetized DataTextField
values..... the actual record's ID is being lost:

0 Mark Rogers
1 Tim Jones
2 Will Smith

Why is this the case? If I remove the ORDER BY clause, it works up until
there is a sequential numbering break in the database's ID field.... so that
the records after the sequential numbering break are off by one. I don't
care really about the latter issue, but found it to be interesting.

Any help is much appreciated!

Thanks,
Brian
 
A

anony

Please disregard this! A note has been made to self that
dropdownlist.SelectedIndex <> dropdownlist.SelectedValue.
 

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,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top