Populate combobox from external function module

2 posts, 0 answers
  1. Fabio
    Fabio avatar
    10 posts
    Member since:
    Sep 2007

    Posted 08 Apr 2011 Link to this post

    Hi,

    I have a radcombobox in a form page:
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            </telerik:RadScriptManager>
            <asp:Button ID="Button1" runat="server" Text="Button" />
            <telerik:RadComboBox ID="cbxProva" runat="server">
            </telerik:RadComboBox>
        </div>
        </form>
    </body>
    </html>

    VB code:

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            cbxProva = CaricaComuni("LE")
        End Sub

     i want to populate the control with external module

    this is the code in the module:
    Public Function CaricaComuni(ByVal Provincia As String) As RadComboBox
           CaricaComuni = New RadComboBox
           Try
               Dim sql As String
     
               sql = "SELECT IdComune, Comune FROM Sys_Comuni WHERE Provincia = @Provincia AND RecordEliminato = 0 ORDER BY Comune"
     
               Dim adapter As New SqlDataAdapter(sql, connStr)
               adapter.SelectCommand.Parameters.Add("@Provincia", SqlDbType.Char).Value = Provincia
               Dim dt As New DataTable()
               adapter.Fill(dt)
     
               CaricaComuni.DataSource = dt
               CaricaComuni.DataTextField = "Comune"
               CaricaComuni.DataValueField = "IdComune"
               CaricaComuni.DataBind()
               CaricaComuni.Items.Insert(0, New RadComboBoxItem("", ""))
     
           Catch ex As Exception
               'MessageBox(ex.Message, ex.StackTrace.Substring(ex.StackTrace.LastIndexOf("\") + 1))
           End Try
       End Function

    When i press the button the debug is good, if i control in debug mode the combox response correctly populate:

    ?cbxProva.Items(1).Text
    "ACQUARICA DEL CAPO"

    But the combobox in the page is empty...

    Why?

  2. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1268 posts

    Posted 13 Apr 2011 Link to this post

    Hi Fabio,

    In order to bind your combobox using custom function as it's in your scenario, you should pass a reference to the existing RadComboBox as an input parameter to this function.

    All the best,
    Dimitar Terziev
    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.

Back to Top