473,499 Members | 1,931 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.Items.Add(new ListItem(myReader["CompanyName"].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 SelectedIndexChanged 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 1650
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**@NOSPAMacordiamn.com> wrote in message
news:%2****************@TK2MSFTNGP10.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.Items.Add(new ListItem(myReader["CompanyName"].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 SelectedIndexChanged 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["CompanyCity"].ToString())
lblState.Text = myReader["CompanyState"].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**@NOSPAMacordiamn.com> wrote in message
news:u$*************@TK2MSFTNGP11.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["CompanyCity"].ToString())
lblState.Text = myReader["CompanyState"].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
5873
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>...
2
11011
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...
0
2488
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...
2
2360
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...
5
4202
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);...
13
2315
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...
2
4548
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...
5
18701
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...
0
1453
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....
0
7180
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
7225
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5479
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,...
1
4920
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...
0
4605
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...
0
3105
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1429
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 ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
307
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.