Populate RadComboBox and select all items on page load

3 posts, 0 answers
  1. Nikos
    Nikos avatar
    8 posts
    Member since:
    Sep 2015

    Posted 17 Mar Link to this post

    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. Dimitar
    Admin
    Dimitar avatar
    281 posts

    Posted 18 Mar Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Nikos
    Nikos avatar
    8 posts
    Member since:
    Sep 2015

    Posted 18 Mar in reply to Dimitar Link to this post

    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

Back to Top