Hi,
check this once
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datalist id="DataList1" runat="server" width="337px" xmlns:asp="#unknown">
<HeaderTemplate>
<table width="100%" align="center">
<tr>
<td>
User ID
</td>
<td>
Product ID
</td>
<td>
Permission
</td>
</tr>
</HeaderTemplate>
<itemtemplate>
<tr>
<td>
<asp:label id="Lbluid" runat="server" text="<%#Eval("userid") %>"></asp:label>
</td>
<td>
<asp:label id="Lblpid" runat="server" text="<%#Eval("proid") %>"></asp:label>
</td>
<td>
<asp:checkbox id="CheckBox1" runat="server" />
</td>
</tr>
</itemtemplate>
<footertemplate>
</footertemplate></table>
</asp:datalist>
<br />
<asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click" xmlns:asp="#unknown" />
</div>
</form>
</body>
</html>
And code behind file contains
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
filldata();
}
}
public void filldata()
{
dt.Columns.Add("userid");
dt.Columns.Add("proid");
addrowin("1", "123");
addrowin("2", "324");
addrowin("5", "67");
addrowin("7", "87");
addrowin("9", "23");
DataList1.DataSource = dt;
DataList1.DataBind();
}
public void addrowin(string uid,string pid)
{
DataRow dr = dt.NewRow();
dr[0] = uid;
dr[1] = pid;
dt.Rows.Add(dr);
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (DataListItem dti in DataList1.Items)
{
string qry="";
string uid = ((Label)dti.FindControl("Lbluid")).Text;
string pid = ((Label)dti.FindControl("Lblpid")).Text;
CheckBox chper=(CheckBox )dti.FindControl ("CheckBox1");
if(chper .Checked )
{
qry = "insert into PermissionTab values ("+uid +","+pid+",'True'";
}
else
{
qry = "insert into PermissionTab values (" + uid + "," + pid + ",'False'";
}
}
}
Now tell me is it correct or not
All the Best