4
Answers

How to insert multiple check check box value in database

Pankaj Kumar

Pankaj Kumar

10y
2.4k
1
ModuleSelect
Home
Abouts
Career
Contact
   
 
Tail me friend how to insert multiple check checkbox value insert into database above fig databse have two field Module And Select how to insert selected colum Add Delete Updated View those are check is insert into database how my code is 
 
 
 
 
Asp Code
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Home.aspx.cs" Inherits="Home" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None">
<Columns>
<asp:BoundField DataField="Module" HeaderText="Module" />
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" Text="Add" runat="server" />
<asp:CheckBox ID="chkAdd" Text="Delete" runat="server" />
<asp:CheckBox ID="CheckBox1" Text="Updated" runat="server" />
<asp:CheckBox ID="CheckBox2" Text="View" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<%-- </asp:TemplateField>
<asp:TemplateField HeaderText="Add">
<ItemTemplate>
<asp:CheckBox ID="chkAdd" Text="ADD" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:CheckBox ID="chkEdit" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="View">
<ItemTemplate>
<asp:CheckBox ID="chkAll" runat="server" />
</ItemTemplate>--%>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
Code Behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Home : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=GANGESH-PC;Initial Catalog=ISB;User ID=sa;Password=sasa");
protected void Page_Load(object sender, EventArgs e)
{
string str = "select Module from Modules";
SqlCommand cmd = new SqlCommand(str,con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
string str = string.Empty;
string strname = string.Empty;
foreach (GridViewRow gvrow in GridView1.Rows)
{
CheckBox chk = (CheckBox)gvrow.FindControl("chkSelect");
if (chk != null & chk.Checked)
{
str += GridView1.DataKeys[gvrow.RowIndex].Value.ToString() + ',';
strname += gvrow.Cells[2].Text + ',';
}
}
}
}
 
 
 
 
 
Answers (4)