473,418 Members | 4,802 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,418 software developers and data experts.

How do i: Databinding 2 database columns to a single dropdown control

Hi,

I want to select an id column and a name column from the database
and have the results databound to a SINGLE dropdown control with the value
property matched to the database id column and the name values on
display to the user. Any idea how i can do this?

Sample HTML showing desired result: Thanks for any help!

<select name="DropDown1" id="DropDown1">
<option value="1">IN</option>
<option value="2">KS</option>
<option value="3">MD</option>
<option value="4">MI</option>
<option value="5">OR</option>
<option value="6">TN</option>

</select>
Nov 19 '05 #1
3 1646
If you get the data into a dataset DSStates with a table tblStates, then
the dropdownlist will look like the following:

<asp:dropdownlist id=ddlLocation Runat="server" DataTextField="Name" DataValueField="Id"
DataMember="tblStates" DataSource="<%# DSStates %>"></asp:dropdownlist>

Eliyahu
Hi,

I want to select an id column and a name column from the database
and have the results databound to a SINGLE dropdown control with the
value
property matched to the database id column and the name values on
display to the user. Any idea how i can do this?
Sample HTML showing desired result: Thanks for any help!

<select name="DropDown1" id="DropDown1">
<option value="1">IN</option>
<option value="2">KS</option>
<option value="3">MD</option>
<option value="4">MI</option>
<option value="5">OR</option>
<option value="6">TN</option>
</select>

Nov 19 '05 #2
Thanks alot....right again!!!!!!
I wanted the intial selection to be nothing .listindex=-1 in vb terms but it
always seems to select first item even if i reset listindex to -1 after
databinding.
HAve i got to load a blank entry as the first item in the dropdownlist?

Thanks a lot!

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:23********************@msnews.microsoft.com.. .
If you get the data into a dataset DSStates with a table tblStates, then
the dropdownlist will look like the following:

<asp:dropdownlist id=ddlLocation Runat="server" DataTextField="Name"
DataValueField="Id" DataMember="tblStates" DataSource="<%# DSStates
%>"></asp:dropdownlist>

Eliyahu
Hi,

I want to select an id column and a name column from the database
and have the results databound to a SINGLE dropdown control with the
value
property matched to the database id column and the name values on
display to the user. Any idea how i can do this?
Sample HTML showing desired result: Thanks for any help!

<select name="DropDown1" id="DropDown1">
<option value="1">IN</option>
<option value="2">KS</option>
<option value="3">MD</option>
<option value="4">MI</option>
<option value="5">OR</option>
<option value="6">TN</option>
</select>


Nov 19 '05 #3
Hi,

I found this code snipet to do the trick after data binding!

DropDownList1.Items.Insert(0, New ListItem("", "-1"))

Thanks!

"John Blair" <jo********@hotmail.com> wrote in message
news:Vf**************@newsfe2-win.ntli.net...
Thanks alot....right again!!!!!!
I wanted the intial selection to be nothing .listindex=-1 in vb terms but
it always seems to select first item even if i reset listindex to -1 after
databinding.
HAve i got to load a blank entry as the first item in the dropdownlist?

Thanks a lot!

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:23********************@msnews.microsoft.com.. .
If you get the data into a dataset DSStates with a table tblStates, then
the dropdownlist will look like the following:

<asp:dropdownlist id=ddlLocation Runat="server" DataTextField="Name"
DataValueField="Id" DataMember="tblStates" DataSource="<%# DSStates
%>"></asp:dropdownlist>

Eliyahu
Hi,

I want to select an id column and a name column from the database
and have the results databound to a SINGLE dropdown control with the
value
property matched to the database id column and the name values on
display to the user. Any idea how i can do this?
Sample HTML showing desired result: Thanks for any help!

<select name="DropDown1" id="DropDown1">
<option value="1">IN</option>
<option value="2">KS</option>
<option value="3">MD</option>
<option value="4">MI</option>
<option value="5">OR</option>
<option value="6">TN</option>
</select>



Nov 19 '05 #4

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

Similar topics

8
by: Kris Rockwell | last post by:
Hello, I have done the following to bind data to a DropDown box: 1. Drag SQLServer table onto web form to create data connection and data adapter. 2. Generate dataset by right-clicking on...
10
by: Krista Lemieux | last post by:
I'm new to ASP.NET and I'm not use to the way things are handled with this technology. I've been told that when I have a control, I should only bind the data to it once, and not on each post back...
3
by: Kevin Swanson | last post by:
I'm writing what should be a very simple app against an Oracle database. The app has a number of user controls, any one of which is loaded into a main display page using the loadControl method,...
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
2
by: John R. Lewis | last post by:
I posted this yesterday with a different email address. I am reposting with my fake-address as given to me by Microsoft so that I can be guraranteed a response from a support representative. Sorry...
1
by: CorporateCoder | last post by:
Hi, I am trying to bind the selected value of a databound dropdown box in a databound gridview control to the value being displayed in the template column the dropdown box has been added to. ...
1
by: Larry Bud | last post by:
Newbie here, so be gentle. I've tried writing this page a variety of ways, but can't get this to work. I have a drop down with monetary exchange rates. I have a table with a bunch of columns...
1
by: Mundo | last post by:
Hi I'm pulling my hair out with a problem caused when DataBinding a DataSet to a web control. I first tried using a GridView but when that failed, I tried a Repeater. I'm getting the classic...
0
by: Chris | last post by:
I am using databinding on a pair of cascading dropdowns. You select a team and get the office they can work in. When I try to rebind the second office dropdown I get the following error. ...
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...
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
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
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...

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.