Default All Checkboxes 'True'

3 posts, 0 answers
  1. gonewalkabout
    gonewalkabout avatar
    12 posts
    Member since:
    Oct 2006

    Posted 28 Jul 2011 Link to this post

    I have 2 List Boxes. One with State the other with City. The City Listbox has Checkboxes. 
    I am trying to find a way to have all the checkboxes 'checked' as the default when the page opens with a State Default selected.
    For example ... When the page opens the State Selected Value is 'WA' and all the cities in Washington are displayed with checkboxes. Works fine.
    But I want them displayed with Checkboxes 'Checked'

    I have tried the collection method:
    If Not Page.IsPostBack Then
        rlbAreas.SelectedValue = "F50"
        Dim collection As IList(Of RadListBoxItem) = rlbSubAreas.Items
        For Each item As RadListBoxItem In Collection
    
           item.Checked = True
    
       
    Next End If

    But the collection at this point returns 0 items. I tried rebinding the rlbSubAreas listbox but that didn't work either.

    Anyone?
  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 03 Aug 2011 Link to this post

    Hi Gonewalkabout,

    Is the second listbox populated based upon the selection of the first listbox? You are on the right way, however, you've to make sure that the second listbox is bound when iterating among its items. If you share with us when exactly the second listbox is databound we will set up a sample demonstrating how to select all the items.

    Greetings,
    Genady Sergeev
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 03 Aug 2011 Link to this post

    Hi Gonewalkabout,

    I'm not sure if this is the problem, but I see a typo in your code.

    Try changing this:
    Dim collection As IList(Of RadListBoxItem) = rlbSubAreas.Items
    For Each item As RadListBoxItem In Collection

    to this:
    Dim collection As IList(Of RadListBoxItem) = rlbSubAreas.Items
    For Each item As RadListBoxItem In collection  '// note lower case c in collection

    I honestly would have expected this to throw an exception rather than keep on going, but it's been a while since I used VB.Net so I could be missing something.  :-)

    Hopefully this helps you out!
    Thad
Back to Top