473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Drop down list indexing problem

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
Nov 18 '05 #1
1 1102
Please disregard this! A note has been made to self that
dropdownlist.SelectedIndex <> dropdownlist.SelectedValue.
"anony" <no**@m.com> wrote in message
news:Yd*********************@twister.tampabay.rr.c om...
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

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: KK | last post by:
Drop-down menus are the hottest thing since Wonder Bread but . . . 1. Alot of people put them in the they-look-nice-but-you-cant-code-them-right-so-they-always-look-messed-up category (a la...
3
by: Don Wash | last post by:
Hi There! I have a Server-side Drop-down box in ASP.NET (VB) page. What do I do to widen the Drop down box's Pull-Down list's width? I'm not talking about the Drop-down box's width but the box...
13
by: Leszek Taratuta | last post by:
Hello, I have several drop-down lists on my ASP.NET page. I need to keep data sources of these lists in Session State. What would be the most effective method to serialize this kind of data...
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...
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
4
by: Laura K | last post by:
I have a drop down menu which has a list of subcategories and the initial value is "please choose a Subcategory". When the user chooses a subcategory they are taken to a new page where the drop...
4
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
3
by: jcassan | last post by:
Hello folks. I am new to these forums and have something, which has been stumping me for little while. I am using pspell to spellcheck a scrolling textbox (textarea) containing user input. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.