Multiple Selection of radcombobox

4 posts, 0 answers
  1. Edd
    Edd avatar
    37 posts
    Member since:
    Jan 2013

    Posted 14 Nov 2013 Link to this post

    Good day,
    please am using a radcombobox that allows for multiple selection.
    My problem is how can i insert the selected items into a database one by one.
    Can someone please help me
    thank you
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Nov 2013 Link to this post

    Hi Edd,

    Please have a look into the code snippet to insert the Selected Item of RadComboBox into DataBase on RadButton OnClick event.

    <telerik:RadComboBox ID="RadComboBox1" runat="server" CheckBoxes="true">
            <telerik:RadComboBoxItem Text="Australia" runat="server" />
            <telerik:RadComboBoxItem Text="Austria" runat="server" />
            <telerik:RadComboBoxItem Text="Bahrain" runat="server" />
            <telerik:RadComboBoxItem Text="Bangladesh" runat="server" />
            <telerik:RadComboBoxItem Text="Belgium" runat="server" />
            <telerik:RadComboBoxItem Text="Bhutan" runat="server" />
    <telerik:RadButton ID="RadButton1" runat="server" Text="Get Selected Item" OnClick="RadButton1_Click">

    protected void RadButton1_Click(object sender, EventArgs e)
        foreach (RadComboBoxItem item in RadComboBox1.Items)
            if (item.Checked == true)
                String connstring = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
                SqlConnection conn = new SqlConnection(connstring);
                SqlCommand cmd = new SqlCommand("insert into CountryTable (CountryName) values('" + item.Text + "')", conn);

  3. Luis
    Luis avatar
    11 posts
    Member since:
    Nov 2009

    Posted 14 Jun Link to this post

    And how can I get the items from a column in a SQL Server table? 


  4. Doncho
    Doncho avatar
    72 posts

    Posted 17 Jun Link to this post

    Hi Luis,

    You can check out the different DataSources that can be used for binding data to the RadComboBox in the Data Binding Overview | RadComboBox article.

    Note that the RadComboBox uses a DataSource and has no direct relation to the SQL database itself.

    Here is a sample of binding a single column DataTable to the RadComboBox

    VB code:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim connstring As String = WebConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
            Dim conn As SqlConnection = New SqlConnection(connstring)
            Dim myCommand As SqlDataAdapter = New SqlDataAdapter("SELECT DISTINCT [Country] FROM [Customers]", conn)
    Dim dt As DataTable = New DataTable() myCommand.Fill(dt)
    RadComboBox1.DataSource = dt RadComboBox1.DataTextField = "Country" RadComboBox1.DataValueField = "Country" RadComboBox1.DataBind() End If

    I hope this will prove helpful!

    Kind regards,
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top