CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009
    Posts
    109

    Unable to get list of checked items from CheckboxList

    I have tried various methods to retrieve the checked items from the CheckboxList, but have failed to do so. I've searched google but have had little luck there as well. Most of the examples given online talk about CheckboxList.Items[i].Select or Checkboxlist.SelectedItem, but those methods aren't really useful in my case, because once you click on a button or something else, the CheckboxList loses focus. So at that point 'SelectedItem' is basically null.

    Here's my code:

    Code:
            private void insertEnquiry()
            {
                List<ECMS_Enquiry> objECMS_Enquiry = new List<ECMS_Enquiry>();
    
                int i = 0;
                for (i = 0; i < chklstbxCourses.Items.Count; i++)
                {
                    if (chklstbxCourses.Items[i].Selected)
                    {
                        Response.Write("<script>alert('" + chklstbxCourses.Items[i].Text + "')</script>");
    
                        objECMS_Enquiry[i].Name = txtName.Text;
                        objECMS_Enquiry[i].Email = txtEmail.Text;
                        objECMS_Enquiry[i].Course = chklstbxCourses.Items[i].Text;
                        objECMS_Enquiry[i].Slot = drpdnlstSlot.Text;
                        objECMS_Enquiry[i].Availability = Calendar1.SelectedDate.ToString();
                        objECMS_Enquiry[i].Sponsorship = drpdnlstSponsorship.Text;
                    }
                }
    
                int result = ECMS_Enquiry.Insert(objECMS_Enquiry);
    
                if (result == 0)
                {
                    Response.Write("<script>alert('Enquiry inserted successfully')</script>");
                }
                else
                {
                    Response.Write("<script>alert('Unable to insert enquiry')</script>");
                }
                
            }
    Just so you know, 'ECMS_Enquiry' is a class that I've constructed separately.

    I've used the same method that I've seen online since I don't know any other methods. Can someone help me?

    If there's any more information that I haven't provided, please let me know. I shall provide it for you.

    Thanks in advance.

    I tried posting this in ASP.NET category as well, but didn't get any reply. I figured since this is both ASP.NET and C# related, i might as well post it here also.

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Unable to get list of checked items from CheckboxList

    It has been a while since I have worked with a checked list box but if memory serves there should be a checked property which is what you would need to check for.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Dec 2009
    Posts
    109

    Re: Unable to get list of checked items from CheckboxList

    Checked property is available only with CheckedListBox (System.Windows.Forms), not with CheckboxList(System.Web.UI.WebControls).

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured