473,467 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Binding two data columns to one DropDownList


Is there a way to bind two columns from a table to one DropDownList?

Below I have the column ["DNAME"] databound to DropDownList1

and would like to also have the column ["LOC"] bound to the same
DropDownList1 from the Dept table. Can this be done?

Have a dropdownlist with DNAME and right next to it LOC in the same
Dropdownlist.

Any suggestions would be appreciated.

Thanks.

bebop

Code I'm using:

HTML:

<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 40px; POSITION:
absolute; TOP: 96px" runat="server" Text="Button"></asp:Button>
<aspropDownList id="DropDownList1" style="Z-INDEX: 102; LEFT: 40px;
POSITION: absolute; TOP: 40px" runat="server"
Width="320px"></aspropDownList></form>

C# Code behind:

private void Button1_Click(object sender, System.EventArgs e)
{
OracleDataAdapter myda = new OracleDataAdapter("select * from
dept","server=localhost;user id=scott;password=tiger");

DataSet ds = new DataSet();
myda.Fill(ds,"DEPT");

//DataSet ds2 = new DataSet();
//myda.Fill(ds2,"DEPT");

DropDownList1.DataSource =ds.Tables[0];
DropDownList1.DataTextField
=ds.Tables[0].Columns["DNAME"].ColumnName.ToString();

//DropDownList1.DataTextField =
ds2.Tables[0].Columns["LOC"].ColumnName.ToString();
DropDownList1.DataValueField
=ds.Tables[0].Columns["DEPTNO"].ColumnName.ToString();

DropDownList1.DataBind();


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
1 5309
hi
I don't think you can do that. What you can do is to
create you own new table with only one data column. Then iterate throw your
original table and add the string value of the two columns to the news
column of the new table . Then bind that column to the DropDownList. When
the user select a value, still you can use the same index of the new table
to refer to records in your original table since it will have exactly the
same values at the same index
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #2

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

Similar topics

0
by: ani | last post by:
Hi, I have a datalist control and within the Itemplate I have a radiobuttonlist control . I am binding data to the datalist control in Page_load . Also I have sqldatareader object that needs...
0
by: HNguyen | last post by:
Hi, I have a problem of binding data from XQuery to a dataset. Here is the program I've extracted from 4guysfromrolla.com. This program read data from an XML file (Employees.xml) and performed...
1
by: mr2_93 | last post by:
Hi All, I am new to ASP.NET and I am looking for help with the dropdownlist data control. I wonder if someone could show me how to past the SelectedValue of a data-bind dropdownlist to...
3
by: abc my vclass | last post by:
There are some programs written on .NET 1.1. These applications are apply n-tiers contains Data Access Layers or Business Logic Layer. Now, our company upgrade to .NET 2.0 and enhance or rewrite...
1
by: jharikrishna | last post by:
Hi frnds How to bind data from dropdownlist and listbox to datagrid
5
by: RAB | last post by:
I have the following code: <%@ Page Language="VB" %> <script runat="server"> Function GetName() As System.Data.IDataReader Dim connectionString As String = 'path to datasource Dim...
2
by: canoewhiteh2o | last post by:
I am having trouble adding data columns to a disconnected database. I first load a datatable using: private DataTable dtMacros = new DataTable(); private ArrayList macro = new ArrayList();...
1
by: suganya | last post by:
Hi I have "Specialty" table with 2 fields (SPID,Specialty). To bind data from "Specialty: table to the dropdownlist during page load, I have given the following coding protected void...
2
by: pavanip | last post by:
Hi, I have a problem with binding data to dropdownlist from database in alphabetical order. My database contains some fields like All,Air,Airline,Books,Cars etc. There are 2 dropdown...
2
ndhamecha
by: ndhamecha | last post by:
i have a problem in binding values with dropdownlist.i have one dropdownlist name,dropdowndiagnosticcategory..i have made one function bind_category() for binding the category values.The code for...
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
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...
1
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
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,...
0
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.