By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

Copying bind Dropdownlist

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.