Thanks,
It works fine now.
jeby
-----Original Message-----
From: Ray Jezek (TT) [mailto:ray.jezek@t...]
Sent: Tuesday, July 16, 2002 7:27 PM
To: ASPX_Professional
Subject: [aspx_professional] Re: populating a dropdownlist
Well I don't think I am doing anything special here... but here is my
code
that renders a DD from a database:
SqlConnection myConn =3D new
SqlConnection(connectionString);
SqlCommand myCommand =3D myConn.CreateCommand();
myCommand.CommandText =3D sql;
myConn.Open();
SqlDataReader myReader =3D
myCommand.ExecuteReader(CommandBehavior.CloseConnection);
AccountDropDown.DataSource =3D myReader;
AccountDropDown.DataValueField =3D
"AccountRegionID";
AccountDropDown.DataTextField =3D
"AccountRegionName";
AccountDropDown.DataBind();
ListItem defaultItem =3D new ListItem("-- Select
Account --","0");
AccountDropDown.Items.Insert(0,defaultItem);
myReader.Close();
AccountRegionID is a SQL Server int and AccountRegionName is a SQL
Server
varchar (actually it's a concatenation of 2 varchars). I use this same
basic code for about 10 ascx's that contain data-bound dd's in my site.
MAKE SURE YOU SPELL BOTH COLUMNS EXACTLY RIGHT AS THEY CORRELATE TO YOUR
SQL
STATEMENT!!!
Hope it helps.
-----Original Message-----
From: jeby [mailto:jeby@c...]
Sent: Tuesday, July 16, 2002 2:19 AM
To: ASPX_Professional
Subject: [aspx_professional] Re: populating a dropdownlist
It seem to work fine if I am using any other list control except
dropdownlist and listbox control!!!!!
Any advice is much appreciated!!
jeby
-----Original Message-----
From: Ray Jezek (TT) [mailto:ray.jezek@t...]
Sent: Monday, July 15, 2002 11:19 PM
To: ASPX_Professional
Subject: [aspx_professional] Re: populating a dropdownlist
I have only used a datareader for my drop downs and it has always worked
for
me. I *think* the behavior seen in the initial post in this thread is
caused by have the wrong column name specified or perhaps the column
being
of the wrong data type. It's been a while since I have handled that
error,
but it was something I did wrong like that.
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Monday, July 15, 2002 12:45 PM
To: ASPX_Professional
Subject: [aspx_professional] Re: populating a dropdownlist
> Hello. Of course it is possible! Set the dropdownlists datasource
> property
Yes, I have had no success when trying to use a DataReader as a
DataSource for a DropDownList. I was forced to write my own
DropDownList
and inherit it from System.Web.UI.WebControls.DropDownList. I really
only
overrided the DataBind() void:
public override void DataBind()
{
if (this.DataSource is System.Data.OleDb.OleDbDataReader)
{
// code here to iterate the reader and properly
// create new ListItems and add them as necessary
}
else
base.DataBind();
}
Anyone actually have the the DropDownList work with a DataReader
out
of the box?
- Chuck
-----Original Message-----
From: jeby [mailto:jeby@c...]
Sent: Monday, July 15, 2002 6:59 AM
To: ASPX_Professional
Subject: [aspx_professional] Re: populating a dropdownlist
I tried this way..But the values which got populated were
System.Data.Common.DBDataRecord
Help!!
-----Original Message-----
From: philip.hatt@a... [mailto:philip.hatt@a...]
Sent: Monday, July 15, 2002 11:56 AM
To: ASPX_Professional
Subject: [aspx_professional] Re: populating a dropdownlist
Hello. Of course it is possible! Set the dropdownlists datasource
property
to the datareader. You can also set the datavalue and datatextfields
property.
Ex:
dropdown.datasource =3D dr 'datareader
dropdown.datatextfield =3D "name"
dropdown.datavaluefield =3D "id"
dropdown.databind()
Philip
> Is it possible to populate a dropdown control with the data source as
datareader or should I strictly use dataset?
Best Regards,
Jeby George
COMPUSOL Software Pvt. Ltd.=3D20
Bangalore - 560 004, INDIA.
Phone (O) + 91 80 650 2107, 652 5434.
Visit Us at http://www.compusolsoftware.com
Email: jeby@c...
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they are
addressed. If you have received this email in error please notify the
system manager and resend it to the sender and delete the mail. Any
review, retransmission, dissemination or other use of, or taking of any
action in reliance upon, this information by persons or entities other
than the intended recipient is prohibited. Please note that any views or
opinions presented in this email are solely those of the author and do
not necessarily represent those of the company. Finally, the recipient
should check this email and any attachments for the presence of viruses.
The company accepts no liability for any damage caused by any virus
transmitted by this email