protected void GvRowCommand(object sender, GridViewCommandEventArgs e)
        {
            string editpage = "~/ControlRoom/Modules/Security/GroupsAddEdit.aspx";

            if (e.CommandName.ToLower() == "addrecord")
            {
                Session["GID"] = string.Empty;
                Response.Redirect(editpage);
            }
            if (e.CommandName.ToLower() == "editrecord")
            {
                int key = Convert.ToInt32(e.CommandArgument);
                Session["GID"] = key; Response.Redirect(editpage);
            }
            if (e.CommandName.ToLower() == "deleterecord")
            {
                int key = Convert.ToInt32(e.CommandArgument);
                try
                {
                    var obj = new SRPGroup(key);
                    if (obj.IsValid(BusinessRulesValidationMode.DELETE))
                    {
                        SRPGroup.Delete(key);

                        LoadData();
                        var masterPage = (IControlRoomMaster)Master;
                        if (masterPage != null)
                        {
                            masterPage.PageMessage = SRPResources.DeleteOK;
                        }
                    }
                    else
                    {
                        var    masterPage = (IControlRoomMaster)Master;
                        string message    = String.Format(SRPResources.ApplicationError1, "<ul>");
                        foreach (BusinessRulesValidationMessage m in obj.ErrorCodes)
                        {
                            message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage);
                        }
                        message = string.Format("{0}</ul>", message);
                        if (masterPage != null)
                        {
                            masterPage.PageError = message;
                        }
                    }
                }
                catch (Exception ex)
                {
                    var masterPage = (IControlRoomMaster)Master;
                    if (masterPage != null)
                    {
                        masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message);
                    }
                }
            }
        }
        protected void DvItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            string returnURL = "~/ControlRoom/Modules/Security/GroupsList.aspx";

            if (e.CommandName.ToLower() == "back")
            {
                Response.Redirect(returnURL);
            }
            if (e.CommandName.ToLower() == "refresh")
            {
                try
                {
                    odsSRPGroups.DataBind();
                    dv.DataBind();
                    dv.ChangeMode(DetailsViewMode.Edit);

                    MasterPage.PageMessage = SRPResources.RefreshOK;
                }
                catch (Exception ex)
                {
                    MasterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message);
                }
            }

            if (e.CommandName.ToLower() == "add" || e.CommandName.ToLower() == "addandback")
            {
                try
                {
                    SRPGroup obj = new SRPGroup();

                    //obj.GID = int.Parse(          ((Label)((DetailsView)sender).FindControl(".GID")).Text    );
                    obj.GroupName        = ((TextBox)((DetailsView)sender).FindControl("GroupName")).Text;
                    obj.GroupDescription = ((TextBox)((DetailsView)sender).FindControl("GroupDescription")).Text;

                    obj.AddedDate   = DateTime.Now;
                    obj.AddedUser   = ((SRPUser)Session[SessionData.UserProfile.ToString()]).Username;    //"N/A";  // Get from session
                    obj.LastModDate = obj.AddedDate;
                    obj.LastModUser = obj.AddedUser;

                    obj.TenID = (int)CRTenantID;

                    if (obj.IsValid(BusinessRulesValidationMode.INSERT))
                    {
                        obj.Insert();
                        if (e.CommandName.ToLower() == "addandback")
                        {
                            Response.Redirect(returnURL);
                        }

                        lblGID.Text = obj.GID.ToString();

                        odsSRPGroups.DataBind();
                        dv.DataBind();
                        dv.ChangeMode(DetailsViewMode.Edit);

                        MasterPage.PageMessage = SRPResources.AddedOK;
                    }
                    else
                    {
                        string message = String.Format(SRPResources.ApplicationError1, "<ul>");
                        foreach (BusinessRulesValidationMessage m in obj.ErrorCodes)
                        {
                            message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage);
                        }
                        message = string.Format("{0}</ul>", message);
                        MasterPage.PageError = message;
                    }
                }
                catch (Exception ex)
                {
                    MasterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message);
                }
            }
            if (e.CommandName.ToLower() == "save" || e.CommandName.ToLower() == "saveandback")
            {
                try
                {
                    SRPGroup obj = new SRPGroup();
                    int      pk  = int.Parse(((DetailsView)sender).Rows[0].Cells[1].Text);
                    obj = SRPGroup.Fetch(pk);


                    obj.GroupName        = ((TextBox)((DetailsView)sender).FindControl("GroupName")).Text;
                    obj.GroupDescription = ((TextBox)((DetailsView)sender).FindControl("GroupDescription")).Text;

                    obj.LastModDate = DateTime.Now;
                    obj.LastModUser = ((SRPUser)Session[SessionData.UserProfile.ToString()]).Username;      //"N/A";  // Get from session

                    if (obj.IsValid(BusinessRulesValidationMode.UPDATE))
                    {
                        obj.Update();

                        SaveUsers((DetailsView)sender, obj);
                        SavePermissions((DetailsView)sender, obj);

                        if (e.CommandName.ToLower() == "saveandback")
                        {
                            Response.Redirect(returnURL);
                        }
                        odsSRPGroups.DataBind();
                        dv.DataBind();
                        dv.ChangeMode(DetailsViewMode.Edit);

                        MasterPage.PageMessage = SRPResources.SaveOK;
                        MasterPage.PageMessage = SRPResources.AddedOK;
                    }
                    else
                    {
                        string message = String.Format(SRPResources.ApplicationError1, "<ul>");
                        foreach (BusinessRulesValidationMessage m in obj.ErrorCodes)
                        {
                            message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage);
                        }
                        message = string.Format("{0}</ul>", message);
                        MasterPage.PageError = message;
                    }
                }
                catch (Exception ex)
                {
                    MasterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message);
                }
            }
        }