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

Populate RadComboBox and select all items on page load

2 Answers 783 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Nikos
Top achievements
Rank 1
Nikos asked on 17 Mar 2016, 09:46 AM

Hi!

i am trying to populate and select all items of the following RadComboBox:

<telerik:RadDropDownList ID="RadDropDownParameterX" runat="server" 
                    DropDownHeight="120px" Width="120px" Skin="BlackMetroTouch" DropDownWidth="120px"
                    OnSelectedIndexChanged="RadDropDownParameterX_SelectedIndexChanged"
                    AutoPostBack="true" >
                    <Items>
                        <telerik:DropDownListItem Text="Countries" Value="Countries" Selected="true" />
                        <telerik:DropDownListItem Text="Sites" Value="Sites" />
                        <telerik:DropDownListItem Text="Rts" Value="Rts" />
                        <telerik:DropDownListItem Text="Machines" Value="Machines" />
                        <telerik:DropDownListItem Text="Protocols" Value="Protocols" />
                    </Items>
                </telerik:RadDropDownList>

With the following code/logic:

Protected Sub Page_Load(sender As Object, e As System.EventArgs)
 
        If Not Page.IsPostBack Then
 
            LoadCountries()
 
            Dim collectionAllCountries As IList(Of RadComboBoxItem)
                collectionAllCountries = RadComboBoxCountries.Items
                For Each item As RadComboBoxItem in collectionAllCountries
                    item.Selected = true
            Next
...
...
...
 
Public Sub LoadCountries()
 
        Dim ListaAllCountries As List(Of AffideaGeneralWeb.BLL.General.Countries)
        ListaAllCountries = AffideaGeneralWeb.BLL.General.Countries.GetCountries()
 
        Dim dataCountries As DataTable = New DataTable()
        dataCountries.Columns.Add("text")
        dataCountries.Columns.Add("value")
 
        For Each c As AffideaGeneralWeb.BLL.General.Countries In ListaAllCountries
 
            Dim currentRow As DataRow = dataCountries.NewRow()
            currentRow("text") = c.Title
            currentRow("value") = c.ID
            dataCountries.Rows.Add(currentRow)
 
        Next
 
        RadComboBoxCountries.DataSource = dataCountries
        RadComboBoxCountries.DataBind()
 
    End Sub

However even if items are populated (so LoadCountries() works and binds datasource to RadComboBox) the code that i am using to select items does not select them in fact (check screenshot)!

Am i missing something here?

2 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 18 Mar 2016, 09:05 AM
Hi,

In order to select all RadComboBox items when using checkboxes, you need to set the Checked property of each of them to true, instead of Selected, in your codebehind. This should do the trick. You may refer to the RadComboBox CheckBox Support help article for additional reference.

And as a side note, the markup provided is of a RadDropDownList, while the codebehind is targeting a RadComboBox.

Regards,
Dimitar
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Nikos
Top achievements
Rank 1
answered on 18 Mar 2016, 12:06 PM

Thanks alot for your answer. Its working now with: 

 

Dim collectionAllCountries As IList(Of RadComboBoxItem)
                collectionAllCountries = RadComboBoxCountries.Items
                For Each item As RadComboBoxItem in collectionAllCountries
                    item.Checked = true
            Next

Indeed have pasted wrong telerik control (RadDropDownList instead of my Combobox) ...

Thanks

Tags
ComboBox
Asked by
Nikos
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Nikos
Top achievements
Rank 1
Share this question
or