473,320 Members | 1,945 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,320 software developers and data experts.

Copying bind Dropdownlist

I have a dropdown list that binds data from a data reader bo I have a second
dropdown list in my wen form which I want to have same data, how can I copy
the one is bind to a secopnd one.. see my code below it dos not work..

Thanks

try

{

SqlConnection MyConnection = new SqlConnection();
MyConnection.ConnectionString = "user id=ScaleClient; password=
XXXAA;Initial Catalog=swatime;Data Source=Carbon";
MConnection.Open();

if(!IsPostBack)
{
SqlCommand MyCommand;
SqlDataReader MyReader;
String MySQL;
MySQL = "select * from clients";
MyCommand = new SqlCommand(MySQL,MyConnection);
MyReader = MyCommand.ExecuteReader();

//Fill Dropdownlist

FinOwnerList.DataSource = MyReader;
FinOwnerList.DataValueField = "ClientName";
FinOwnerList.DataBind();
// set Owner from Clients
PrjOwner.DataSource = MyReader;
PrjOwner.DataValueField = "ClientName";
PrjOwner.DataBind();
}
}


Nov 19 '05 #1
2 2324
Hi Carlos,

Are you trying to fill the second list with items from the first list? If
so, take a look at this?

http://www.metabuilders.com/Tools/DualList.aspx

"Carlos" <cp@swa.com> wrote in message
news:eb**************@TK2MSFTNGP10.phx.gbl...
I have a dropdown list that binds data from a data reader bo I have a
second dropdown list in my wen form which I want to have same data, how can
I copy the one is bind to a secopnd one.. see my code below it dos not
work..

Thanks

try

{

SqlConnection MyConnection = new SqlConnection();
MyConnection.ConnectionString = "user id=ScaleClient; password=
XXXAA;Initial Catalog=swatime;Data Source=Carbon";
MConnection.Open();

if(!IsPostBack)
{
SqlCommand MyCommand;
SqlDataReader MyReader;
String MySQL;
MySQL = "select * from clients";
MyCommand = new SqlCommand(MySQL,MyConnection);
MyReader = MyCommand.ExecuteReader();

//Fill Dropdownlist

FinOwnerList.DataSource = MyReader;
FinOwnerList.DataValueField = "ClientName";
FinOwnerList.DataBind();
// set Owner from Clients
PrjOwner.DataSource = MyReader;
PrjOwner.DataValueField = "ClientName";
PrjOwner.DataBind();
}
}


Nov 19 '05 #2
Hi Carlos,

Yes, the second DropDownList is empty because the DataReader is forward
only and after bind with the first DropDownList, it's cursor point to the
end of the ResultSet and won't be able to bind with any other control
again. If you do need to populate the second dropdownlist by resuing the
datas binding to the first DropDownList(without requery the db to fill the
datareader), you can consider bind the second dropdownlist with the First
DropDownList's Items Collection. For exampLe:

if(!IsPostBack)
{
conn.Open();
SqlDataReader dr = comm.ExecuteReader();

this.lstOne.DataSource = dr;
this.lstOne.DataTextField = "fname";
this.lstOne.DataValueField = "emp_id";
this.lstOne.DataBind();

this.lstTwo.DataSource = lstOne.Items;
this.lstTwo.DataTextField = "Text";
this.lstTwo.DataValueField = "Value";
this.lstTwo.DataBind();
}

HTH.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #3

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

Similar topics

2
by: COHENMARVIN | last post by:
I'm leafing through a big book on asp.net, and I don't see any way to the following: 1. bind values and text to a dropdown 2. Also make the first line of the dropdown say something different. For...
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...
1
by: Patrik Zdarsa | last post by:
Hi, I'm try VS 2005 and need UPDATE database record in viewform, all working when every filed is type TextBox (html INPUT) but I need change one TextBox to Listbox or dropdownlist and read data...
3
by: sck10 | last post by:
Hello, I am trying to bind an arraylist to a FormView DropDownList control in the PreRender state. The error that I get is the following: Databinding methods such as Eval(), XPath(), and...
0
by: Mark Micallef | last post by:
Hi, I'm having a problem using a databound dropdownlist inside a reorderlist ajax control. Here's a snippet of the code I'm using: <InsertItemTemplate> <div class="insertArea">...
1
by: Mark Micallef | last post by:
Hi, this question relates to a control in the Ajax toolkit for asp.net 2. I'm having a problem using a databound dropdownlist inside a reorderlist ajax control. Here's a snippet of the code I'm...
1
by: iswar | last post by:
Hi friends.. Im trying to bind a value from dropdownlist placed in gird view to another cell. i want to update a database field with the selected value from dropdownlist and which must be bind to...
1
by: sweatha | last post by:
Hi Friends I have designed a form with 1 DropDownList box named “ddlShow_time”& the form name is “Default4.aspx”. Just like that, I have the database(SQL SERVER 2000) as Table Name: ShowTime...
2
by: akshalika | last post by:
Hi, I have a repeater control. it dynamically bind textbox or dropdown base on some condition. i want to bind required field validator dynamically for validate textbox or dropdown. here is my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.