CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2012

    dropdownlist-how to check the value from in list in the table

    error in the below code-connot imlicitly convert type string to 'System.Web.UI.WebControls.ListItem'

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
            SqlConnection cn=myClass.DBCon();
            SqlCommand cmd=new SqlCommand("select CourseName from Course",cn);
            SqlDataReader dr=cmd.ExecuteReader();
            while (dr.Read())
                if (DropDownList1.SelectedItem = dr["CourseName"].ToString())
    Last edited by GremlinSA; February 15th, 2012 at 02:34 AM. Reason: added code tags.

  2. #2
    Join Date
    Jun 2005
    JHB South Africa

    Re: dropdownlist-how to check the value from in list in the table

    The problem here is that DropDownList1.SelectedItem is of Type ListItem and does not immediately return the selected Value..

    you have several options here ... If your looking for the DDL's selected text you can use :..

    Or if your looking for the Value behind you can use either:.

    NOTE : All the above returned types are string....
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.