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

Populate combobox from external function module

1 Answer 55 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Fabio
Top achievements
Rank 2
Fabio asked on 08 Apr 2011, 03:18 PM
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?

1 Answer, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 13 Apr 2011, 03:38 PM
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.

Tags
ComboBox
Asked by
Fabio
Top achievements
Rank 2
Answers by
Dimitar Terziev
Telerik team
Share this question
or