<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type = "text/javascript"> function check_click(objRef) { //Get the Row based on checkbox var col = objRef.parentNode; if (objRef.checked) { check_click.Enabled = true; } } </script>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <asp:Label ID="Label5" runat="server" Text="Label"> <br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Height="250px" style="font-family: Verdana; font-size: small" Width="677px" onselectedindexchanged="GridView1_SelectedIndexChanged" GridLines="None"> <alternatingrowstyle backcolor="#E8E8E8" /> <columns> <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" /> <asp:BoundField DataField="Pages" HeaderText="Pages" /> <asp:TemplateField HeaderText="Add" SortExpression="Add"> <itemtemplate> <asp:CheckBox ID="Add" runat="server" onclick="Javascript:check_click(this)"/> </itemtemplate> <asp:TemplateField HeaderText="View" SortExpression="View"> <itemtemplate> <asp:CheckBox ID="View" runat="server" /> </itemtemplate> <asp:TemplateField HeaderText="Edit" SortExpression="Edit"> <itemtemplate> <asp:CheckBox ID="Edit" runat="server" /> </itemtemplate> <asp:TemplateField HeaderText="Delete" SortExpression="Delete"> <itemtemplate> <asp:CheckBox ID="Delete" runat="server" /> </itemtemplate> </columns> <HeaderStyle BackColor="#EBEBEB" /> <asp:Button ID="Button7" runat="server" onclick="Button7_Click" Text="Save" /> <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator" ClientValidationFunction="check_click">Required <br />
protected void Button7_Click(object sender, EventArgs e) { foreach (GridViewRow row in GridView1.Rows) { if (row.RowType == DataControlRowType.DataRow) { if (Session["Role_Name"] != null && !string.IsNullOrEmpty(Session["Role_Name"].ToString())) { CheckBox chkAdd = (row.Cells[2].FindControl("Add") as CheckBox); CheckBox chkEdit = (row.Cells[3].FindControl("View") as CheckBox); CheckBox chkView = (row.Cells[4].FindControl("Edit") as CheckBox); CheckBox chkDelete = (row.Cells[5].FindControl("Delete") as CheckBox); // string strID = row.Cells[0].Text; string ID = row.Cells[0].Text; string Pages = row.Cells[1].Text; con.Open(); string query = "Update Role1 set [Add]='" + (chkAdd.Checked == true ? 'Y' : 'N') + "', [View]='" + (chkView.Checked == true ? 'Y' : 'N') + "' ,[Edit]='" + (chkEdit.Checked == true ? 'Y' : 'N') + "' ,[Delete]='" + (chkDelete.Checked == true ? 'Y' : 'N') + "' where Pages ='" + Pages + "' and Role_Name='" + Session["Role_Name"].ToString() + "'and ID='" + ID + "'"; SqlCommand cmd = new SqlCommand(query, con); cmd.ExecuteNonQuery(); con.Close(); } } } populateGridview(); GridView1.DataBind(); }
<asp:CheckBox ID="View" runat="server" EnableViewState="true" />
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)