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
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