private void dgPermissions_UpdateCommand(object source, DataGridCommandEventArgs e)
		{
			//Cell Index is the index of permissionID
			int CompanyPermissionID = Convert.ToInt32( e.Item.Cells[0].Text);

			BPCompanyGroups bp = new BPCompanyGroups();
			DSCompanyGroups = bp.SelectCompanyGroupPermissionsByCompanyGroupID(CompanyGroupID);

			BECompanyGroups.tbl_CompanyGroupPermissionsRow groupPermission = DSCompanyGroups.tbl_CompanyGroupPermissions.FindByCompanyGroupIDCompanyPermissionID(CompanyGroupID, CompanyPermissionID);

			DropDownList lstPermValues = (DropDownList) e.Item.FindControl("lstPermValues");
			groupPermission.CompanyGroupPermissionValue = Convert.ToInt16(lstPermValues.SelectedValue);

			bp.UpdateCompanyGroupPermissions(DSCompanyGroups);

			DSCompanyGroups = bp.SelectCompanyGroupPermissionsByCompanyGroupID(CompanyGroupID);

			dgPermissions.EditItemIndex = -1;
			dgPermissions.SelectedIndex = -1;
			dgPermissions.DataBind();
		}
		private void btnDone_Click(object sender, EventArgs e)
		{
			if (_HasChangedUsers )
			{
				BPCompanyGroups BPCompanyGroups = new BPCompanyGroups();
			
				if (_HasChangedUsers )
				{
					DSCompanyGroups = BPCompanyGroups.SelectCompanyGroupPermissionsByCompanyGroupID(CompanyGroupID);
					ArrayList perms = new ArrayList(PermList);
					perms.Sort();

					//Remove Duplicates
					if (perms.Count > 1)
					{
						int iLast,iCurrent;
						iLast = (int) perms[0];
						for (int i=1; i<perms.Count; i++)
						{
							iCurrent = (int) perms[i];

							if (iCurrent == iLast)
							{
								perms.RemoveAt(i);
							}
							iLast = iCurrent;
						}
					}

					int searchIndex;
					foreach (BECompanyGroups.tbl_CompanyGroupPermissionsRow groupPerm in DSCompanyGroups.tbl_CompanyGroupPermissions)
					{
						searchIndex = perms.BinarySearch(groupPerm.CompanyPermissionID);
						if (searchIndex < 0)
							//if (Array.BinarySearch(groupPerm.PermissionID))
						{
							//Not Found
							groupPerm.Delete();
						}
						else
						{
							perms.RemoveAt(searchIndex);
						}
					}

					foreach (int i in perms)
					{
						BECompanyGroups.tbl_CompanyGroupPermissionsRow groupPerm;
						groupPerm = DSCompanyGroups.tbl_CompanyGroupPermissions.FindByCompanyGroupIDCompanyPermissionID(CompanyGroupID, i);
						if(groupPerm == null)
						{
							groupPerm = DSCompanyGroups.tbl_CompanyGroupPermissions.Newtbl_CompanyGroupPermissionsRow();
							groupPerm.CompanyGroupID = CompanyGroupID;
							groupPerm.CompanyPermissionID = i;
							groupPerm.CompanyGroupPermissionValue = 2;
							DSCompanyGroups.tbl_CompanyGroupPermissions.Addtbl_CompanyGroupPermissionsRow(groupPerm);
						}

						//The first value for a permission should always be 1.
						groupPerm.CompanyGroupPermissionValue = 2;
					}
				}

				BPCompanyGroups.UpdateCompanyGroupPermissions(DSCompanyGroups);
				DSCompanyGroups = BPCompanyGroups.SelectCompanyGroupPermissionsByCompanyGroupID(CompanyGroupID);
				dgPermissions.DataBind();
			}
			pnlAssign.Visible = false;
			pnlPermissions.Visible = true;

			tab1.Attributes["class"] = "";
			tab2.Attributes["class"] = "current";
		}