protected void ctlBtnAdd_Click1(object sender, EventArgs e)
 {
     CtlUserRoleEditor1.Initialize(FlagEnum.NewFlag, 0);
     CtlUserRoleEditor1.ShowPopUp();
 }
        protected void ctlGridRole_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            InvisibleAllPopUpcontrol();
            int rowIndex = 0;

            if (e.CommandName == "RoleDelete")
            {
                try
                {
                    rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
                    short  roleID = short.Parse(ctlGridRole.DataKeys[rowIndex].Value.ToString());
                    SuRole role   = SuRoleService.FindByIdentity(roleID);
                    SuRoleService.DeleteRole(role);
                }
                catch (ServiceValidationException ex)
                {
                    ValidationErrors.MergeErrors(ex.ValidationErrors);
                }
                catch (Exception ex)
                {
                    if (((System.Data.SqlClient.SqlException)(ex.GetBaseException())).Number == 547)
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertinusedata",
                                                                "alert('this data is now in use.');", true);
                    }
                }

                ctlGridRole.DataCountAndBind();
            }
            if (e.CommandName == "RoleEdit")
            {
                //find role id for current setup.

                rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
                short roleID = short.Parse(ctlGridRole.DataKeys[rowIndex].Value.ToString());
                CtlUserRoleEditor1.Initialize(FlagEnum.EditFlag, roleID);
                CtlUserRoleEditor1.ShowPopUp();
            }
            if (e.CommandName == "PB")
            {
                //find role id for current setup.
                rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
                short roleID = short.Parse(ctlGridRole.DataKeys[rowIndex].Value.ToString());

                ctlPBInfo1.Initialize(roleID);
                ctlPBInfo1.Show();
            }

            if (e.CommandName == "Service")
            {
                //find role id for current setup.
                rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
                short roleID = short.Parse(ctlGridRole.DataKeys[rowIndex].Value.ToString());
                ctlServiceTeamInfo1.Initialize(roleID);
                ctlServiceTeamInfo1.Show();
            }

            if (e.CommandName == "Program")
            {
                //find role id for current setup.
                rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
                short roleID = short.Parse(ctlGridRole.DataKeys[rowIndex].Value.ToString());

                ctlProgramInfo1.Initialize(roleID);
                ctlProgramInfo1.Show();
            }

            ctlGridRole.SelectedIndex = rowIndex;
            ctlUpdPanelGridView.Update();
            // แก้ไขการกด link ในกริด ที่จะเป็น Editor มาในหน้าเดียวกัน ไม่ต้องทำการ CountAndBind จะทำให้ไม่เกิด Event ในการกด Link ครั้งต่อไป
            //ctlGridRole.DataCountAndBind();


            //try
            //{
            //    int selectIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
            //    //ctlGridRole.Rows[selectIndex].BackColor = Color.WhiteSmoke;

            //}
            //catch (Exception)
            //{

            //}
        }