Unable to find the checked items in checked combobox

714 views Asked by At

I am using a checked combobox for selecting multiple items. Following is the code am using

ASP.Net

<telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1">
  <telerik:RadComboBox ID="cbo_tagtofilelist" runat="server" CheckBoxes="true" 
Style="width: 157px; height: 15px" ExpandDirection="Down" EnableCheckAllItemsCheckBox="true" 
value="date" Skin="WebBlue">
  </telerik:RadComboBox>
</telerik:RadAjaxPanel>

VB.Net

  Private Sub lnkfiletag_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkfiletag.Click
        ShowCheckedItems(cbo_tagtofilelist)
 End Sub
    Private Shared Sub ShowCheckedItems(ByVal comboBox As RadComboBox)
        Dim msSQL As String = " insert into selecteditems( fileid, name ) values"
        For Each chkeitems As RadComboBoxItem In comboBox.CheckedItems
            If chkeitems.Checked = True Then
                msSQL &= " ('" & fid & "', '" & chkeitems.Value & "'),"
            End If
        Next
        msSQL = msSQL.Substring(0, Len(msSQL) - 1)
        con.OpenConn()
        con.ExecuteNonQuerySQL(msSQL)
        con.CloseConn()
   End Sub

But using this code I am unable to find the selected items and insert into the database. Item count always be 0 on button click, what am I doing wrong with this code

1

There are 1 answers

0
Rahul Nikate On BEST ANSWER

Bind your RadComboBox in Page_Init also.

Here's Code :

Protected Sub Page_init(sender As Object, e As EventArgs)
     RadComboBox1.DataSource = list
     'Your DataSource Here
     RadComboBox1.DataTextField = "TextField"
     RadComboBox1.DataValueField = "ValueField"
     RadComboBox1.DataBind()
End Sub

Please find more information here.