protected void btnAdd_Click(object sender, EventArgs e) { try { string territoryCode; //changes maded by Harish - 27-10-16 //if (!string.IsNullOrWhiteSpace(txtNewTerritory.Text) & !string.IsNullOrWhiteSpace(txtNewTerritoryLoc.Text)) if (string.IsNullOrWhiteSpace(txtNewTerritory.Text) & string.IsNullOrWhiteSpace(txtNewTerritoryLoc.Text)) { msgView.SetMessage("Please select a territory to add to the groups", MessageType.Warning, PositionType.Auto); } else { if (!string.IsNullOrWhiteSpace(txtNewTerritory.Text)) { territoryCode = txtNewTerritory.Text.Substring(0, txtNewTerritory.Text.IndexOf("-") - 1); } else { territoryCode = txtNewTerritoryLoc.Text.Substring(0, txtNewTerritoryLoc.Text.IndexOf("-") - 1); } string territoryGroupCode; List <string> territoryGroupCodes = new List <string>(); foreach (GridViewRow gridrow in gvTerritoryGroup.Rows) { territoryGroupCode = (gridrow.FindControl("lblTerritoryGroupCode") as Label).Text; territoryGroupCodes.Add(territoryGroupCode); } if (territoryGroupCodes.Count > 0) { string userCode = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()); territorySearchBL = new TerritorySearchBL(); territorySearchBL.AddTerritoryToGroups(territoryCode, territoryGroupCodes.ToArray(), userCode, out errorId); territorySearchBL = null; if (errorId == 0) { msgView.SetMessage("New territory has been added to the groups", MessageType.Warning, PositionType.Auto); } else { ExceptionHandler("Error in adding the territory to groups.", ""); } } } mpeInsertGroup.Show(); } catch (Exception ex) { ExceptionHandler("Error in adding the territory to groups.", ex.Message); } }