Click here to Skip to main content
15,914,074 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a windows form which loads all data from a table (tblMinistries) and displays it in a checklistbox. This work works correctly, now i have another table (tblNewministries) and i want all the items in the table (tblNewministries) to be checked automaticaly in the checkedlistbox when it is populated. table (tblNewministries) is a subset of table (tblMinistries)
Please help me out

code
public void PopuMinistry22()
        {
            SqlConnection conn = new SqlConnection("Data Source=USER-PC;Initial Catalog=PIWCDB;User ID=sa;Password=mike");
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            string SqlDataPull = ("select Homecellname from tblministries order by Homecellname");
            SqlCommand cmd = new SqlCommand(SqlDataPull);
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                SqlDataPull = dr[0].ToString();
                cblMinistries.Items.Add(SqlDataPull);
            }
            dr.Close();
        }
Posted

If you have id with checkboxes then you can do this using jqury in document.ready() by using the code.
JavaScript
$('#myCheckbox').prop('checked', true);
$('#myCheckbox').prop('checked', false);
 
Share this answer
 
You could use a left outer join, something like
SQL
select tblMinistries.Homecellname, case when tblNewMinistries.Homecellname isnull then 0 else 1 end as checked from tblMinistries left outer join tblNewMinistries on tblMinistries.Homecellname = tblNewMinistries.Homecellname order by tblMinistries.Homecellname

This way you would retrieve both the item and its checked state (as 0 or 1).
 
Share this answer
 
Comments
mikeoabban 7-May-14 6:49am    
i get this errors- An expression of non-boolean type specified in a contex where a condition is expected near isnull

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