Multiple Selection of radcombobox

2 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.

    ASPX:
    <telerik:RadComboBox ID="RadComboBox1" runat="server" CheckBoxes="true">
        <Items>
            <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" />
        </Items>
    </telerik:RadComboBox>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Get Selected Item" OnClick="RadButton1_Click">
    </telerik:RadButton>

    C#:
    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);
                conn.Open();
                SqlCommand cmd = new SqlCommand("insert into CountryTable (CountryName) values('" + item.Text + "')", conn);
                cmd.ExecuteNonQuery();
                conn.Close();
            }
        }
        Response.Write("<script>alert('Inserted')</script>");
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top