Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
    CellPadding="4" ForeColor="#333333" GridLines="None" 
    onrowdeleting="GridView2_RowDeleting" onrowdatabound="OnRowDataBound">
    <alternatingrowstyle backcolor="White" />
    <columns>
        <asp:TemplateField HeaderText="Edit">
            <itemtemplate>
                <asp:Image ID="Image1" alt = "" style="cursor: pointer" runat="server" ImageUrl="~/plus.png" />
                    <asp:Panel ID="pnlOrders" runat="server" Style="display: none">
                     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    CellPadding="4" ForeColor="#333333" 

    GridLines="None" OnItemDataBound="GridView1_ItemDataBound"
Width="693px"  Font-Bold="False" onpageindexchanged="Button3_Click" >
   
    <alternatingrowstyle backcolor="White" />
    <columns>
        <asp:BoundField HeaderText="ID" DataField="ID" >
        <HeaderStyle BackColor="#F7D5FF" Font-Size="8.5pt" ForeColor="Black" />
        
        <asp:BoundField HeaderText="Pages" DataField="Pages" >
        <HeaderStyle BackColor="#F7D5FF" Font-Bold="True" Font-Size="8.5pt" 
            ForeColor="Black" />
        
        <asp:TemplateField HeaderText="ADD">
            <itemtemplate>
                <asp:CheckBox ID="CheckBox1" runat="server" 
                    EnableViewState="False" AutoPostBack="True" />
            </itemtemplate>
            <HeaderStyle BackColor="#F7D5FF" Font-Bold="True" Font-Size="8.5pt" 
                ForeColor="Black" />
        
        <asp:TemplateField HeaderText="View">
            <itemtemplate>
                <asp:CheckBox ID="CheckBox2" runat="server" />
            </itemtemplate>
            <HeaderStyle BackColor="#F7D5FF" Font-Size="8.5pt" ForeColor="Black" />
        
        <asp:TemplateField HeaderText="Edit">
            <itemtemplate>
                <asp:CheckBox ID="CheckBox3" runat="server" />
            </itemtemplate>
            <HeaderStyle BackColor="#F7D5FF" Font-Size="8.5pt" ForeColor="Black" />
        
        <asp:TemplateField HeaderText="Delete">
            <itemtemplate>
                <asp:CheckBox ID="CheckBox4" runat="server" />
            </itemtemplate>
            <HeaderStyle BackColor="#F7D5FF" Font-Size="8.5pt" ForeColor="Black" />
        
    </columns>
    <editrowstyle backcolor="#2461BF" />
    <footerstyle backcolor="#507CD1" font-bold="True" forecolor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <pagerstyle backcolor="#2461BF" forecolor="White" horizontalalign="Center" />
    <rowstyle backcolor="#EFF3FB" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <sortedascendingcellstyle backcolor="#F5F7FB" />
    <sortedascendingheaderstyle backcolor="#6D95E1" />
    <sorteddescendingcellstyle backcolor="#E9EBEF" />
    <sorteddescendingheaderstyle backcolor="#4870BE" />

   <asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="Save" />                
    
                 
            </itemtemplate>
        
        <asp:TemplateField HeaderText="Role_ID">
            <itemtemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("Role_ID") %>'>
            </itemtemplate>
        
        <asp:TemplateField HeaderText="Role_Name">
            <itemtemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Bind("Role_Name") %>'>
            </itemtemplate>
        
        <asp:TemplateField HeaderText="Description">
            <itemtemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Bind("Description") %>'>
            </itemtemplate>
        
        <asp:TemplateField HeaderText="Delete">
            <itemtemplate>
                <asp:ImageButton CssClass="txtBtn" ID="lnkDelete" runat="server" CommandName="Delete"
                    CommandArgument='' OnClientClick="javascript:return confirm('Are you sure you want to delete the record?')"
                    ImageUrl="~/images/icon_delete.gif" ToolTip="Delete" />
           
            </itemtemplate>
        
    </columns>
    <editrowstyle backcolor="#2461BF" />
    <footerstyle backcolor="#507CD1" font-bold="True" forecolor="White" />
    <HeaderStyle BackColor="#F7D5FF" Font-Bold="True" ForeColor="Black" />
    <pagerstyle backcolor="#2461BF" forecolor="White" horizontalalign="Center" />
    <rowstyle backcolor="#EFF3FB" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <sortedascendingcellstyle backcolor="#F5F7FB" />
    <sortedascendingheaderstyle backcolor="#6D95E1" />
    <sorteddescendingcellstyle backcolor="#E9EBEF" />
    <sorteddescendingheaderstyle backcolor="#4870BE" />

code
C#
protected void Button3_Click(object sender, EventArgs e)
{
    foreach (GridViewRow ro in GridView2.Rows)
    {
        if (ro.RowType == DataControlRowType.DataRow)
        {
            GridView gv = (GridView)ro.FindControl("GridView1");
            {
                if (gv != null)
                {
                    foreach (GridViewRow row in gv.Rows)
                    {
                        if (row.RowType == DataControlRowType.DataRow)
                        {
                            for (int i = 0; i < gv.Rows.Count; i++)
                            {
                                Label ID = (ro.Cells[1].FindControl("Label1") as Label);
                                int Role_ID = Convert.ToInt32(ID.Text);
                                CheckBox chkAdd = (row.Cells[2].FindControl("CheckBox1") as CheckBox);
                                CheckBox chkEdit = (row.Cells[3].FindControl("CheckBox2") as CheckBox);
                                CheckBox chkView = (row.Cells[4].FindControl("CheckBox3") as CheckBox);
                                CheckBox chkDelete = (row.Cells[5].FindControl("CheckBox4") as CheckBox);
                                string strID = row.Cells[0].Text;
                                string Pages = row.Cells[1].Text;

                                con.Open();
                                string query = "Update Role1 set Role_ID= '" + Role_ID + "',  [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 [ID]='" + strID + "'  and Pages ='" + Pages + "'";
                                SqlCommand cmd = new SqlCommand(query, con);
                                cmd.ExecuteNonQuery();
                                gv.DataBind();

                                con.Close();
                            }
                        }
                    }
                }
            }
        }
    }
}
Posted
v2
Comments
While debugging, see if the values are coming correctly inside the Button Click or not?
Member 10578683 31-Mar-14 3:20am    
no values are not coming correctly

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900