���This is needlessly complicated.� Why are you looping instead of databinding?
From: imane elfechtani [EMAIL PROTECTED]
Thank you friends, and sorry for delay, I managed to fill the drop down list
using datareader, and here is my code I hope it will help someone who has same
problem:
get list function to get the list of items to fil the drop down:
public void getList()
{
myConnection= connectMe.connect ();
myCommand = query.CreateMySqlCommand ("SELECT cityName FROM VM_CITY",
myConnection);
SqlDataReader myReader = myCommand.ExecuteReader();
// Always call Read before accessing data.
while(myReader.Read ())
{
//get fron DB
//string codeDB = myReader.GetSqlDecimal(0).ToString ();
string cityDB = myReader.GetString(0);
citiesDdl.Items.Add (cityDB);
}
// always call Close when done reading.
myReader.Close();
}
////////////////////
Then I cal it in page_upload
private void Page_Load(object sender, System.EventArgs e)
{
//error.Text="connected";
if(!IsPostBack)
{
this.getList();
}
}
////////////
regards
Rajendra Appalla wrote:
Try setting the datatextfield and datavaluefield properties of
dropdonwlist control.
Rajendra.
_____
From: imane elfechtani [mailto:[EMAIL PROTECTED]
Sent: Monday, February 21, 2005 10:58 AM
To: [email protected]
Subject: RE: [AspNetAnyQuestionIsOk] problem filling a drop down list
from a dataset
hello,
Thank you for your responde. I do not get erros..
I detected that this code doesn't work first because I
have put it into a try catch and it executes teh
catch, also because I do not get the data into the
drop down list.
I do not understand what's the problem, maybe I am
using the dataset in the wrong way!
do you have any documentation of how I can use
datasets to fill dropdown lists?
Regards
Thanks
--- Peter Brunone wrote:
> Imane,
>
> You need to tell us what doesn't work. Are you
> getting an
> error? If so, what is the error message and what
> line of code does it
> indicate?
>
> Once we know whether the problem is with the data
> itself or with
> the dropdownlist, we can help more.
>
> Cheers,
>
> Peter Brunone
> ___________________
> www.EasyListBox.com
>
> -----Original Message-----
> From: imane elfechtani
> [mailto:[EMAIL PROTECTED]
>
> Hello everybody,
>
> I have problem filling a drop down list from a
> dataset.
>
> here is my peice of code that doesnt work:
> con is my connection that I have declared, query is
> a
> string, ds is a dataset , allCities is my
> dropdown...
>
> con = dbc.connect();
> query ="select cityName from VM_CITY";
> SqlDataAdapter comm = new SqlDataAdapter(query,
> con);
> DataSet ds = new DataSet();
> comm.Fill(ds);
> allCities.DataSource = ds;
> allCities.DataBind();
>
> would anyone help me plz
>
> Thanks :)
>
> Imane
[Non-text portions of this message have been removed]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/