473,626 Members | 3,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filling a drop down from a database?

I have a drop down list on a web page that I pre-fill onload from a SQL
table using a SqlDataReader.

The line of code that fills the drop down looks like this

while(myReader. Read())
{
ddlCompany.Item s.Add(new ListItem(myRead er["CompanyNam e"].ToString(),
myReader["CompanyID"].ToString()))
}
Now my problem is I have labels that I want to pre-fill with the information
from the first Company record in the table, but I am not sure how to do
that. If a user selects a different company from the drop down then I can
easily change all the labels in a SelectedIndexCh anged event, but how can I
get them on the load of the page?

I hope what I am asking makes sense. Basically what I need to do is capture
all the data from the first record that the reader gets and output it into
the labels.
Nov 18 '05 #1
3 1658
Hey,

Check the DDLCompanyList. Items.Count. If it is > 0 then you have more than
one record

Once you are done loading data from reader in to the DDL, query the
list.count property and
you can always query whats in the list by DDL.items[0].Text &
DDL.items[0].Value
That should give you your first companys info....

Regards,

Hermit Dave

"Russ" <ru**@NOSPAMaco rdiamn.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I have a drop down list on a web page that I pre-fill onload from a SQL
table using a SqlDataReader.

The line of code that fills the drop down looks like this

while(myReader. Read())
{
ddlCompany.Item s.Add(new ListItem(myRead er["CompanyNam e"].ToString(),
myReader["CompanyID"].ToString()))
}
Now my problem is I have labels that I want to pre-fill with the information from the first Company record in the table, but I am not sure how to do
that. If a user selects a different company from the drop down then I can
easily change all the labels in a SelectedIndexCh anged event, but how can I get them on the load of the page?

I hope what I am asking makes sense. Basically what I need to do is capture all the data from the first record that the reader gets and output it into
the labels.

Nov 18 '05 #2
The sql query that I execute to fill the drop down returns all the fields
from the table but only uses 2 of them in the dropdown.

My page looks like this:

ddlCompany lblAdress lblCity lblState lblZip lblCountry

The dropdown shows the first Company but all the labels are blank. What I
need to figure out is how to pre-fill those labels. If I knew there was
only one record I could use code like this to do it:

myReader.Read()
lblAdress.Text = myReader["CompanyAddress "].ToString())
lblCity.Text = myReader["CompanyCit y"].ToString())
lblState.Text = myReader["CompanySta te"].ToString())
lblZip.Text = myReader["CompanyZip "].ToString())
lblCountry.Text = myReader["CompanyCountry "].ToString())

but in my case I have many records going into the drop down, but only need
the data from the very first one.


Nov 18 '05 #3
Well then y waste memory and processing time...
fetch two sets of results...
first call a procedure to get you the info for your DDL and from the return
query seperately for the first one
see when the user selects the item from ddl you will either way have to run
a query to fetch the results for that index...
might as well use the same query...

Regards,

Hermit Dave

"Russ" <ru**@NOSPAMaco rdiamn.com> wrote in message
news:u$******** *****@TK2MSFTNG P11.phx.gbl...
The sql query that I execute to fill the drop down returns all the fields
from the table but only uses 2 of them in the dropdown.

My page looks like this:

ddlCompany lblAdress lblCity lblState lblZip lblCountry

The dropdown shows the first Company but all the labels are blank. What I
need to figure out is how to pre-fill those labels. If I knew there was
only one record I could use code like this to do it:

myReader.Read()
lblAdress.Text = myReader["CompanyAddress "].ToString())
lblCity.Text = myReader["CompanyCit y"].ToString())
lblState.Text = myReader["CompanySta te"].ToString())
lblZip.Text = myReader["CompanyZip "].ToString())
lblCountry.Text = myReader["CompanyCountry "].ToString())

but in my case I have many records going into the drop down, but only need
the data from the very first one.

Nov 18 '05 #4

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

Similar topics

5
5888
by: Jim Bo | last post by:
Hi, I have a drop down menu that is being populated by a query to the access database ---- Code --- Skill needed <SELECT size="1" NAME="SkillType" VALUE="SkillType"> <OPTION> <%=SkillType%>
2
11036
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic SFSB and, from there, to the database. On the front end, all cells appear as text fields. However, for certain cells, when the user clicks on the cell, the text field turns into a drop-down field (i.e. Select object), defaulting to the value...
0
2495
by: Leigh | last post by:
I am building a data entry application using Java servlets. I had hoped to use drop down boxes to provide the user with data entry selections pulled from a database, but am now questioning, given the latency with which the data loads to the browser, whether drop down boxes are viable for providing a large number of select options. I've put nearly-identical examples of the problem on two different web/database hosts for review (I wanted...
2
2369
by: ramesh | last post by:
hi, I am using Com+ in my application. It will have InsertRecords,selectRecords,updateRecords function. In the Web Form i have Drop-down list. I want to select records from SQL and add it to this list. I know how to fill the data in the drop-down list. But i don't know how to pass this control to Com+. Do we need to pass like private FillList(Object e) {
5
4219
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); System.Data.SqlClient.SqlCommand dbCommand1 = new System.Data.SqlClient.SqlCommand();
13
2342
by: Oliver Hauger | last post by:
Hello, In my html form I show a select-element and if this element is clicked I fill it per JavaScript/DOM with option-elements. I use the following code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head>
2
4553
by: Ren | last post by:
Hi all, I am a bit new to PHP and SQL so this may seem like a dumb question. I have already created a drop down list as part of a form which is automatically populated with values taken from a separate database. When a user goes onto this page and either leaves the default value or selects a value from the drop down list and presses the submit button, I would like that selected value to be stored into a database which I have already...
5
18719
by: ashok893 | last post by:
I'm using two drop down list ina form. I have generated the first drop down list from MySQL database. When i select an option from first drop down list, i have to generate second drop down list options by the selected value of first drop down list from MySQL database. For example, the first drop down list contains Animals, Birds... If i select the Animal option, the second drop down list should show like Lion, Tiger.... Both lists should...
0
1461
by: jaeden99 | last post by:
I have a two drop down list box. The first contains district name(district id is the value) and the the second will contain the user name based on the district selected in the first drop down list. I am trying to code this in vb.net. It is a web based application. I've gotten the district info to load, but I can't figure out how to get the users to load. I've created a stored procedure to get user... Stored procedure info. SELECT...
0
8265
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8705
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8504
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7193
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5574
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2625
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1808
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.