views:

50

answers:

3
ddlSub.Items.Add(new ListItem("--Select --", ""));

gives following error

cannot convert from 'ListItem' to 'string' what is the correct syntax

thanx...

+1  A: 

Are you sure this is the exact line of code?

I just added a dropdownlist to a webform and then named it the same thing as yours and copy and pasted your line of code into the PageLoad.

// in aspx
<asp:DropDownList ID="ddlSub" runat="server"></asp:DropDownList>

// in .cs codebehind
ddlSub.Items.Add(new ListItem("--Select --", ""));

Compiles just fine. You must be leaving something out.

Kelsey
hey...thnx for reply..just missed the System.Web.UI.WebControls in namespaces list...
anay
A: 

It's correct. The error must be when you try to read the value out and expect a ListItem or something similar.

Include more code and we can identify the problem.

Wim Hollebrandse
A: 

hey... thnx for replies.. just missed the System.Web.UI.WebControls in namespaces list...

anay
YOu may want to read the FAQ with StackOverflow.If your question was answered you need to mark it as answered.
JonH