using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class StringTest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SqlDataSource ds = new SqlDataSource(); ds.ConnectionString = ConfigurationManager.ConnectionStrings["cnPPDB"].ToString(); ds.DataSourceMode = SqlDataSourceMode.DataSet; Utilities.populateCombo(ds, boardPortfolioDropDown, "mspBoardPortfolio", "BoardPortfolioID", "BoardPortfolioName"); } protected void SetBPDropDown(string logonUserName) { string boardPortfolioName = ""; string[] rolesArray; rolesArray = Roles.GetRolesForUser(logonUserName); if (rolesArray.Length >= 1) { ArrayList boardPortfolioNameArrayList = new ArrayList(); foreach (string str in rolesArray) { if (str != "ChairBoardPortfolio") { boardPortfolioName = ReadWriteManager.GetUserBoardPortfolio(str); Response.Write("
User in role: " + boardPortfolioName); boardPortfolioNameArrayList.Add(boardPortfolioName); } } bool keepItem; bool matchFound = false; string bpItemStr; for (int x = boardPortfolioDropDown.Items.Count - 1; x > 0; x--) { ListItem bpItem = boardPortfolioDropDown.Items[x]; Response.Write("

BP Item: " + bpItem.ToString()); bpItemStr = bpItem.ToString(); keepItem = false; foreach (string bpName in boardPortfolioNameArrayList) { Response.Write("
BP Name: " + bpName); //if ((bpItemStr == bpName) && (keepItem == false)) //if ((String.Compare(@bpItemStr, @bpName, true) == 0) && (keepItem == false)) if ((bpItemStr.Equals(bpName) && (keepItem == false))) { keepItem = true; matchFound = true; } } if (keepItem == false) { Response.Write("
" + bpItemStr + " Removed"); // Method "Remove" does NOT work for items bounded from DB. Use method "RemoveAt" instead //boardPortfolioDropDown.Items.Remove(bpItemStr); boardPortfolioDropDown.Items.RemoveAt(x); } } if (matchFound == true) { Response.Write("

Match found."); } else { Response.Write("

Match NOT found."); } // If they belong to only one board, set it for them // Need to check for 2 items b/c first item is "Select One" if (boardPortfolioDropDown.Items.Count == 2) { boardPortfolioDropDown.Items.Remove("Select One"); boardPortfolioDropDown.Items.FindByText(boardPortfolioName.ToString()).Selected = true; } } } protected void goButton_Click(object sender, EventArgs e) { //SqlDataSource ds = new SqlDataSource(); //ds.ConnectionString = ConfigurationManager.ConnectionStrings["cnPPDB"].ToString(); //ds.DataSourceMode = SqlDataSourceMode.DataSet; //Utilities.populateCombo(ds, boardPortfolioDropDown, "mspBoardPortfolio", "BoardPortfolioID", "BoardPortfolioName"); // Set up board/portfolio of logged on user SetBPDropDown(userNameTextBox.Text); } }