Pass the value from one value to another combobox

2 posts, 0 answers
  1. Fabio Cirillo
    Fabio Cirillo avatar
    181 posts
    Member since:
    Jan 2010

    Posted 19 Nov 2012 Link to this post

    Hi,

    I pass the value of the value of the item selected from a radcombox to another. The first is radcombox Region and I have to pass the valure the selected region or typed, the second radcombo to load the list of provinces that refer to the region. Here is the code I use hand side aspx and vb net:

    <telerik:RadComboBox ID="Regione" Runat="server" CollapseDelay="100"
        EnableLoadOnDemand="True" HighlightTemplatedItems="True" IsCaseSensitive="True"
        LoadingMessage="Caricamento..." DropDownWidth="160px" Filter="StartsWith" Width="160px"
        MaxHeight="175px" ShowMoreResultsBox="True" Height="175px" AutoPostBack="True">
    </telerik:RadComboBox>
     
     
    <telerik:RadComboBox ID="Provincia" Runat="server" CollapseDelay="100"
        DropDownWidth="170px" EnableLoadOnDemand="True" Filter="StartsWith"
        HighlightTemplatedItems="True" IsCaseSensitive="True"
        LoadingMessage="Caricamento..." MaxHeight="175px" ShowMoreResultsBox="True"
        Width="170px" Height="175px" EmptyMessage="Scegli la regione">
    </telerik:RadComboBox>



        
    Private Const ItemsRegion As Integer = 11
        Private Const ItemsProvincs As Integer = 10
        Private idregione As Integer = 0
    Protected Sub Region_ItemsRequested(sender As Object, e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles Region.ItemsRequested
            Dim data As DataTable = GetDataRegion(e.Text)
            Dim itemOffset As Integer = e.NumberOfItems
            Dim endOffset As Integer = Math.Min(itemOffset + ItemsRegion, data.Rows.Count)
     
            e.EndOfItems = endOffset = data.Rows.Count
            For i As Integer = itemOffset To endOffset - 1
                Region.Items.Add(New RadComboBoxItem(data.Rows(i)("descrizione").ToString(), data.Rows(i)("id").ToString()))
            Next
            e.Message = GetStatusMessageRegion(endOffset, data.Rows.Count)
        End Sub
        Private Shared Function GetDataRegion(text As String) As DataTable
     
            Dim sqlSelectCommand As String = "SELECT [id], [descrizione] from [tab_regioni] WHERE [descrizione] LIKE @desc + '%' Order By [descrizione]"
     
            Dim adapter As New SqlDataAdapter(sqlSelectCommand, ConfigurationManager.ConnectionStrings("TrycontactString").ConnectionString)
            adapter.SelectCommand.Parameters.AddWithValue("@desc", text)
     
            Dim data As New DataTable()
     
            adapter.Fill(data)
     
            Return data
     
        End Function
     
        Private Shared Function GetStatusMessageRegion(offset As Integer, total As Integer) As String
     
            If total <= 0 Then
     
                Return "Regione non trovata"
     
            End If
     
            Return [String].Format("Lista: <b>1</b>-<b>{0}</b> di <b>{1}</b>", offset, total)
     
        End Function
     
        Protected Sub Provincs_ItemsRequested(sender As Object, e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles Provincs.ItemsRequested
            Dim data As DataTable = GetDataProvincs(e.Text, idregione)
            Dim itemOffset As Integer = e.NumberOfItems
            Dim endOffset As Integer = Math.Min(itemOffset + ItemsProvincs, data.Rows.Count)
     
            e.EndOfItems = endOffset = data.Rows.Count
            For i As Integer = itemOffset To endOffset - 1
                Provincs.Items.Add(New RadComboBoxItem(data.Rows(i)("descrizione").ToString(), data.Rows(i)("id").ToString()))
            Next
            e.Message = GetStatusMessageProvincs(endOffset, data.Rows.Count)
        End Sub
        Private Shared Function GetDataProvincs(text As String, id As Int32) As DataTable
     
            Dim sqlSelectCommand As String = "SELECT [id], [idregione], [descrizione] from [tab_province] WHERE [idregione]=@idregione and [descrizione] LIKE @desc + '%' Order By [descrizione]"
     
            Dim adapter As New SqlDataAdapter(sqlSelectCommand, ConfigurationManager.ConnectionStrings("TrycontactString").ConnectionString)
            adapter.SelectCommand.Parameters.AddWithValue("@desc", text)
            adapter.SelectCommand.Parameters.AddWithValue("@idregione", id)
            Dim data As New DataTable()
     
            adapter.Fill(data)
     
            Return data
     
        End Function
     
        Private Shared Function GetStatusMessageProvincs(offset As Integer, total As Integer) As String
     
            If total <= 0 Then
     
                Return "Provincia non trovata"
     
            End If
     
            Return [String].Format("Lista: <b>1</b>-<b>{0}</b> di <b>{1}</b>", offset, total)
     
        End Function

    bye
  2. Nencho
    Admin
    Nencho avatar
    1874 posts

    Posted 22 Nov 2012 Link to this post

    Hi Fabio,

    I can suggest you to use the OnClientSelectedIndexChanged client event of the Regione RadComboBox, to fire the RequestItems event, passing the selection to the second RadComboBox. I have prepared a sample project for you, demonstrating the above suggested approach. Please find the sample attached.

    Greetings,
    Nencho
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top