Please try this:
Step 1:- In my case I use one ListBox(ListBox1),TextBox(TextBox1)(to show the data) and a Button(for save the seleced values in the database)
Step2:- create a table in the database
create table table2
(
list varchar(max)
)
Step3:- set the
AutoPostBack="True"
of the ListBox1 and on the
OnSelectedIndexChanged(event)
we write the following code
TextBox1.Text = TextBox1.Text + ListBox1.SelectedItem.Text;
Step4:- Now on the Button Click Event(for save the value in the database)
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
conn.Open();
SqlCommand cmd1 = new SqlCommand("insert into table1(list) values('" + TextBox1.Text + "')", conn);
cmd1.ExecuteNonQuery();
conn.Close();
Note:-> in the Web.Config File
<connectionStrings>
<add name="con" connectionString="Data Source=my\SQLEXPRESS;Initial Catalog=try;Integrated Security=true;" />
</connectionStrings>