Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a table in my mssql db with 2 columns (homecellid and homecellname) i want all data in homecell to be displayed in a checkboxlist (cblMinistries) i tried this but i keep getting an error “The type or namespace name "ListItem" could not be found” please help me out

private void PopulateMinistires()
        {

                SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
                conn.ConnectionString = "Data Source=USER-PC;Initial Catalog=PIWCDB;User ID=sa;Password=mike";


                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = "select * from tblMinistries";
                    cmd.Connection = conn;
                    conn.Open();
                    using (SqlDataReader sdr = cmd.ExecuteReader())
                    {
                        while (sdr.Read())
                        {
                            ListItem item = new ListItem();
                            item.Text = sdr["Homecellname"].ToString();
                            chkMinistries.Items.Add(item);
                        }
                    }
                    conn.Close();
                }
            
        }
Posted
Updated 31-Mar-14 9:22am
v2

Solution 1 by Richard C. Bishop might help you, but if not, please, refer this: The type or namespace name 'ListItem' could not be found[^].
 
Share this answer
 
Comments
Richard C Bishop 31-Mar-14 16:48pm    
Nice alternative.
Maciej Los 31-Mar-14 16:49pm    
Thank you, Richard ;)
Either add this for Web Forms:
using System.Web.UI.WebControls;


of this for Win Forms:
using System.Windows.Forms;

to the top of your page or use the fully qualified name for the control.
 
Share this answer
 
v2
Comments
Maciej Los 31-Mar-14 16:45pm    
Who voted 1? Good answer, +5!
Richard C Bishop 31-Mar-14 16:46pm    
I know, silly folks. Thank you.
Maciej Los 31-Mar-14 16:49pm    
See my answer ;)
mikeoabban 13-Apr-14 8:14am    
i get the message UI does not exsit in the name space 'system.web'
what should i do
Richard C Bishop 14-Apr-14 10:03am    
Very well, is this a web forms or win forms application?
Hi Mike, see these examples:
Bind CheckBoxList with DataBase[^]
Populate with CheckBoxList[^]

Regards.
 
Share this answer
 
Comments
Maciej Los 31-Mar-14 16:45pm    
Interesting links, +5!
Christian Amado 31-Mar-14 16:51pm    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900