Hello,
I understand how i can use select2 plugin in ASP.Net but what i do not understand is how to get all the value selected and store them into a sql database table.
I look at this example, but i still do not get it.
https://www.aspforums.net/Threads/132523/Get-selected-items-of-multiselect-DropDownList-using-jQuery-Select2-Plugin-in-ASPNet/
I have a Dropdownlist that display data from a db and i have a Textbox field to allow user to imput new item that does not appear in the Dropdownlist. what I am trying to do is if someone select items or wirte the item on the textbox fiel, the items will be stored into a new table.
As of my code, nothing fency,
can someone please advise?
thanks
<asp:DropDownList ID="ddl1" Width="100%" runat="server" multiple="multiple" CssClass="form-control js-example-placeholder-single"
ToolTip="Select" DataSourceID="blablabla" DataValueField="Keyword" DataTextField="Keyword" AppendDataBoundItems="true" >
</asp:DropDownList>
<asp:TextBox ID ="Keyword_enter" runat="server" AutoPostBack="true" Width="100%" >
<asp:Button ID="btnSave" Text="Save " runat="server" OnClick="btnSave_Click" />
protected void btnSave_Click(object sender, EventArgs e)
{
Conn3.Open();
sqlCom.Parameters.Add(new SqlParameter("@Keyword", ddl1.SelectedValue));
sqlCom.ExecuteNonQuery();
if (Keyword_enter.Text.Contains(','))
{
string[] arrayval = Keyword_enter.Text.Trim().Split(',');
int j = arrayval.Length;
int i = 0;
for (i = 0; i < j; i++)
{
sqlCom.Parameters.Clear();
sqlCom.Parameters.AddWithValue("@Keyword", arrayval[i]);
sqlCom.ExecuteNonQuery();
}
Lit2.Text = "recorded ";
Keyword_enter.Text = String.Empty;
}
else
{
Lit2.Text = "Single value entered";
sqlCom.Parameters.Add(new SqlParameter("@Keyword", Keyword_enter.Text));
sqlCom.ExecuteNonQuery();
Keyword_enter.Text = String.Empty;
}