Re: Populating a dropdown listbox problem!
Wayne Lee <[email protected]> Wed, 19 Jun 2002 13:01:24 +0100
| Newsgroups | gmane.comp.windows.devel.dotnet.general |
|---|---|
| Message-ID | <001301c21789$08ea0cb0$0e631e3e@skywalker> |
Well it's because the add method requires a listitem object and not a
string...here
If you're not using data binding and want a quick fix add this after the
first { in your while loop
ListItem li = new ListItem();
li.Value = sEmployClass;
li.Text = sEmployClass;
ddemployeeClassification.Items.Add(li);
There's more that could be done, but this should fix your problem for
now!
Wayne Lee
Evident Systems Ltd
This email has been scanned with Norton AntiVirus 2002
-----Original Message-----
From: The DOTNET list will be retired 7/1/02
[mailto:[email protected]] On Behalf Of dmlegare
Sent: 19 June 2002 12:00
To: [email protected]
Subject: [DOTNET] Populating a dropdown listbox problem!
How do I use my datareader object to populate a dropdownlistbox??? Im
getting conversion type errors..?????? here is the code
string myConnection = "........";
string mySelectQuery = "select employee_class_name from
onlinetime_empclass "; OleDbConnection myConn = new
OleDbConnection(myConnection); OleDbCommand objCommand = new
OleDbCommand(mySelectQuery, myConn); OleDbDataReader objDataReader =
null; myConn.Open(); objDataReader = objCommand.ExecuteReader(); string
sEmployClass = ""; while (objDataReader.Read() == true)
{
*sEmployClass = objDataReader["employee_class_name"];
ddemployeeClassification.Items.Add(sEmployClass);
}
I get an error when i try to view in a browsers:
*Compiler Error Message: CS0029: Cannot implicitly convert type 'object'
to 'string'
You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.