无法在选中的组合框中找到选中的项目

时间:2014-11-25 04:57:36

标签: asp.net vb.net combobox telerik radcombobox

我使用已检查的组合框来选择多个项目。以下是使用

的代码

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

但是使用此代码我无法找到所选项目并插入数据库。按钮点击时项目总数为0,我对此代码的错误

1 个答案:

答案 0 :(得分:0)

将您的RadComboBox绑定在Page_Init中。

此处的代码:

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.