protected void Button1_Click(object sender, EventArgs e)
    {
        main_class mc = new main_class();
        // vvvvv for editing group permission
        if (GridView2.Visible == true)
        {
            for (int i = 0; i < GridView2.Rows.Count; i++)
            {
                int GroupID = (int)GridView2.DataKeys[i][0];
                CheckBox cb = (CheckBox)GridView2.Rows[i].FindControl("chk_select");
                if (cb.Checked)
                {

                    for (int y = 0; y < GridView3.Rows.Count; y++)
                    {
                        int ModuleID = (int)GridView3.DataKeys[y][0];
                        ListItem li = (ListItem)(GridView3.Rows[y].FindControl("ListBox1") as ListBox).SelectedItem;
                        if (li != null)
                        {
                            mc.execute_command(string.Format("delete from tbl_groups_permission where gd_tbl_groups_link={0} and gd_module_link={1}", GroupID.ToString(), ModuleID.ToString()));
                            mc.execute_command(string.Format("insert into tbl_groups_permission (gd_tbl_groups_link,gd_module_link,gd_blocked) values ({0},{1},{2})", GroupID.ToString(), ModuleID.ToString(), li.Value.ToString()));
                        }
                    }
                }
            }
        }

        // vvvvv for editing user permission
        if (GridView1.Visible == true)
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                int UserID = (int)GridView1.DataKeys[i][0];
                CheckBox cb = (CheckBox)GridView1.Rows[i].FindControl("chk_select");
                if (cb.Checked)
                {

                    for (int y = 0; y < GridView3.Rows.Count; y++)
                    {
                        int ModuleID = (int)GridView3.DataKeys[y][0];
                        ListItem li = (ListItem)(GridView3.Rows[y].FindControl("ListBox1") as ListBox).SelectedItem;
                        if (li != null)
                        {
                            mc.execute_command(string.Format("delete from tbl_users_permission where up_user_link={0} and up_module_link={1}", UserID.ToString(), ModuleID.ToString()));
                            mc.execute_command(string.Format("insert into tbl_users_permission (up_user_link,up_module_link,up_blocked) values ({0},{1},{2})", UserID.ToString(), ModuleID.ToString(), li.Value.ToString()));
                        }
                    }
                }
            }
        }
    }
    protected void LinkButton6_Click(object sender, EventArgs e)
    {
        main_class mc = new main_class();
        // vvvvv for editing group permission
        if (rb_user.Checked)
        {
            int GroupTesterID = Convert.ToInt32(Session["TestGroupIDUser"].ToString());
            for (int i = 0; i < gv_usersList.Rows.Count; i++)
            {
                CheckBox cb = (CheckBox)gv_usersList.Rows[i].FindControl("chk_select");
                if (cb.Checked)
                {

                    mc.execute_command(string.Format("delete from tbl_education_tests_user_group_details where etugd_userID_link={0} and etugd_group_link={1}", cb.ToolTip, GroupTesterID.ToString()));
                    mc.execute_command(string.Format("insert into tbl_education_tests_user_group_details (     etugd_userID_link,            etugd_group_link) values ({0},{1})", cb.ToolTip, GroupTesterID.ToString()));

                }
            }
        }

        if (rb_group.Checked)
        {
            int GroupTesterID = Convert.ToInt32(Session["TestGroupIDUser"].ToString());
            for (int i = 1; i < gv_GroupsList.Rows.Count+1; i++)
            {
                CheckBox cb = (CheckBox)gv_GroupsList.Rows[i-1].FindControl("chk_select");
                if (cb.Checked)
                {
                    foreach (DataRow dr in
                        new MainDataModuleTableAdapters.tbl_usersTableAdapter().GetDataByGroupID(
                        Convert.ToInt32(cb.ToolTip)).Rows)
                    {
                        mc.execute_command(string.Format("delete from tbl_education_tests_user_group_details where etugd_userID_link={0} and etugd_group_link={1}", dr["u_id"].ToString(), GroupTesterID.ToString()));
                        mc.execute_command(string.Format("insert into tbl_education_tests_user_group_details (etugd_userID_link,etugd_group_link) values ({0},{1})", dr["u_id"].ToString(), GroupTesterID.ToString()));
                    }
                }
            }
            GridView2.DataBind();
        }
    }