473,396 Members | 2,024 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,396 software developers and data experts.

DropDownList not populating with top row of data

Hi,

I'm attempting to populate a dropdownlist with data from a datareader.
It works OK except whatever data is extracted as the very top line
(Index = 0) cannot be seen in the dropdownlist.

Here is my code:

string strEstNo = Session["establishment"].ToString();

SqlCommand cmd = new SqlCommand("proc_GetSurgeonName", conn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@estNo", strEstNo));

SqlDataReader dr = cmd.ExecuteReader();
dr.Read();

// bind the drop down
surgeonNameCboBx.DataSource = dr;
surgeonNameCboBx.DataTextField = "sgnFullName";
surgeonNameCboBx.DataValueField = "surgeonNo";
surgeonNameCboBx.DataBind();
surgeonNameCboBx.SelectedIndex = 0;

// close datareader
dr.Close();
And here's the stored procedure:

CREATE PROCEDURE proc_GetSurgeonName
(@estNo int
)

AS

SELECT *, sgnTitle + ' ' + sgnFName + ' ' + sgnLName AS sgnFullName
FROM tblSurgeon
WHERE estNo = @estNo
ORDER BY sgnFullName
GO

I have tested this in query analyser, and all expected rows are found.

I noticed when i added in ORDER BY that a different row was missing
than without it, i.e.

List of ID & sgyFullName without ORDER BY sgyFullName shown in dropdown
list:
2 Dr Paul Jones
3 Dr Andrew Thorpe

List of ID & sgyFullName with ORDER BY sgyFullName shown in dropdown
list:
1 Dr Kevin Smith
2 Dr Paul Jones

List using query analyser without ORDER BY:
1 Dr Kevin Smith
2 Dr Paul Jones
3 Dr Andrew Thorpe

Anyone know why the top row isn't being read into the DropDownList?

Thanks

Nov 19 '05 #1
3 1437
Not sure about the "order by stuff". However, I did notice that in the code
you have a "dr.read()" before the databind(). Take out the "dr.Read()". This
reads the first row. Then when the DataBind() is executed it does not get the
first record. (It does a dr.Read() in a loop behind the scenes.

"Assimalyst" wrote:
Hi,

I'm attempting to populate a dropdownlist with data from a datareader.
It works OK except whatever data is extracted as the very top line
(Index = 0) cannot be seen in the dropdownlist.

Here is my code:

string strEstNo = Session["establishment"].ToString();

SqlCommand cmd = new SqlCommand("proc_GetSurgeonName", conn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@estNo", strEstNo));

SqlDataReader dr = cmd.ExecuteReader();
dr.Read();

// bind the drop down
surgeonNameCboBx.DataSource = dr;
surgeonNameCboBx.DataTextField = "sgnFullName";
surgeonNameCboBx.DataValueField = "surgeonNo";
surgeonNameCboBx.DataBind();
surgeonNameCboBx.SelectedIndex = 0;

// close datareader
dr.Close();
And here's the stored procedure:

CREATE PROCEDURE proc_GetSurgeonName
(@estNo int
)

AS

SELECT *, sgnTitle + ' ' + sgnFName + ' ' + sgnLName AS sgnFullName
FROM tblSurgeon
WHERE estNo = @estNo
ORDER BY sgnFullName
GO

I have tested this in query analyser, and all expected rows are found.

I noticed when i added in ORDER BY that a different row was missing
than without it, i.e.

List of ID & sgyFullName without ORDER BY sgyFullName shown in dropdown
list:
2 Dr Paul Jones
3 Dr Andrew Thorpe

List of ID & sgyFullName with ORDER BY sgyFullName shown in dropdown
list:
1 Dr Kevin Smith
2 Dr Paul Jones

List using query analyser without ORDER BY:
1 Dr Kevin Smith
2 Dr Paul Jones
3 Dr Andrew Thorpe

Anyone know why the top row isn't being read into the DropDownList?

Thanks

Nov 19 '05 #2
What happens when it fails? Is there a message? What is displayed in the
browser?

"Assimalyst" wrote:
Hi,

I'm attempting to populate a dropdownlist with data from a datareader.
It works OK except whatever data is extracted as the very top line
(Index = 0) cannot be seen in the dropdownlist.

Here is my code:

string strEstNo = Session["establishment"].ToString();

SqlCommand cmd = new SqlCommand("proc_GetSurgeonName", conn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@estNo", strEstNo));

SqlDataReader dr = cmd.ExecuteReader();
dr.Read();

// bind the drop down
surgeonNameCboBx.DataSource = dr;
surgeonNameCboBx.DataTextField = "sgnFullName";
surgeonNameCboBx.DataValueField = "surgeonNo";
surgeonNameCboBx.DataBind();
surgeonNameCboBx.SelectedIndex = 0;

// close datareader
dr.Close();
And here's the stored procedure:

CREATE PROCEDURE proc_GetSurgeonName
(@estNo int
)

AS

SELECT *, sgnTitle + ' ' + sgnFName + ' ' + sgnLName AS sgnFullName
FROM tblSurgeon
WHERE estNo = @estNo
ORDER BY sgnFullName
GO

I have tested this in query analyser, and all expected rows are found.

I noticed when i added in ORDER BY that a different row was missing
than without it, i.e.

List of ID & sgyFullName without ORDER BY sgyFullName shown in dropdown
list:
2 Dr Paul Jones
3 Dr Andrew Thorpe

List of ID & sgyFullName with ORDER BY sgyFullName shown in dropdown
list:
1 Dr Kevin Smith
2 Dr Paul Jones

List using query analyser without ORDER BY:
1 Dr Kevin Smith
2 Dr Paul Jones
3 Dr Andrew Thorpe

Anyone know why the top row isn't being read into the DropDownList?

Thanks

Nov 19 '05 #3
Thanks Brad, That was what was strange there were no errors etc. just
the missing row.

Removing the dr.Read() line seems to have fixed that though.

Thanks again.

Nov 19 '05 #4

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

Similar topics

12
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
1
by: Ravi | last post by:
I am trying to represent master-detail records from a database The general logic will be populating the first dropdownlist with the master records and on change of the first dropdownlis getting...
1
by: Ravi | last post by:
I am trying to represent master-detail records from a database The general logic will be populating the first dropdownlist with the master records and on change of the first dropdownlis getting...
2
by: Dave | last post by:
Hi, I'm building a maintenance form for a table and some of the fields are textboxes (i.e name) and some should be dropdowns (i.e country of origin) When a user clicks 'Edit' in the...
1
by: Wim | last post by:
Hi Everyone, I'm trying to speed up a Asp.net 1.1 applications' performance. The application needs to run in an environment with little bandwith and therefore pagesizes and roundtrip times shoud...
3
by: RFS666 | last post by:
Hello together, I tried to find out about populating an asp.net server control (a dropdownlist) from the clientside jscript, but I didn't find a solution up to now. I cannot use a html...
3
by: Iain | last post by:
Hi All I have 2 DropDownList boxes on a page. The first (id= "Operation") is populated on PageLoad with the contents of a database table. The second id="WorkStations" will not be populated...
0
by: koonda | last post by:
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my...
2
by: Aswanth | last post by:
Hi.. I'm using Asp.Net with C#.... I'm having One Dropdownlist control(Users_Details_DDL) in Default.aspx Page... i'm having one Stored Procedure (Get_User_Email) which will display the Data...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.