Hi Asifpatel,
I have created sample code by refering the below article which full-fill your requirement.
HTML
<form id="form1" runat="server">
<div>
Employee Names:
<br />
<asp:ListBox ID="ListBox1" runat="server" Height="149px" SelectionMode="Multiple"
Width="113px">
<asp:ListItem>Vinz</asp:ListItem>
<asp:ListItem>Jhen</asp:ListItem>
<asp:ListItem>Chris</asp:ListItem>
<asp:ListItem>Shynne</asp:ListItem>
<asp:ListItem>Chu</asp:ListItem>
<asp:ListItem>Mark</asp:ListItem>
<asp:ListItem>Lilian</asp:ListItem>
<asp:ListItem>Rod</asp:ListItem>
<asp:ListItem>Glendzy</asp:ListItem>
</asp:ListBox>
</div>
<br />
<asp:Button ID="Button1" runat="server" Text="Save" OnClick="Button1_Click" />
</form>
C#
private string GetConnectionString()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
}
protected void Button1_Click(object sender, EventArgs e)
{
string strEmployeeName = string.Empty;
foreach (ListItem item in ListBox1.Items)
{
if (item.Selected)
{
strEmployeeName += item.Text + ",";
}
}
InsertRecords(strEmployeeName.Remove(strEmployeeName.Length - 1));
}
private void InsertRecords(string employeeName)
{
SqlConnection conn = new SqlConnection(GetConnectionString());
SqlCommand cmd = new SqlCommand("INSERT INTO EmployeesTest Values(@EmployeeName)", conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@EmployeeName", employeeName);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Script", "alert('Records Successfuly Saved!');", true);
}
Screenshot
