This is a migrated thread and some comments may be shown as answers.

Default All Checkboxes 'True'

2 Answers 91 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 28 Jul 2011, 04:44 PM
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 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 03 Aug 2011, 08:12 AM
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.

0
Thad
Top achievements
Rank 2
answered on 03 Aug 2011, 12:14 PM
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
Tags
ListBox
Asked by
Craig
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Thad
Top achievements
Rank 2
Share this question
or