Binding two data columns to one DropDownList

C

cw bebop

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();
 
M

Mohamoss

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top