當前位置: 首頁>>代碼示例>>C#>>正文


C# ListItemCollection.Contains方法代碼示例

本文整理匯總了C#中System.Web.UI.WebControls.ListItemCollection.Contains方法的典型用法代碼示例。如果您正苦於以下問題:C# ListItemCollection.Contains方法的具體用法?C# ListItemCollection.Contains怎麽用?C# ListItemCollection.Contains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Web.UI.WebControls.ListItemCollection的用法示例。


在下文中一共展示了ListItemCollection.Contains方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Methods

		public void Methods ()
		{
			ListItemCollection	c;
			ListItem		i;
			ListItem		i2;

			c = new ListItemCollection();
			Assert.AreEqual (0, c.Count, "T1");

			i = new ListItem("Item 1", "10");
			c.Add(i);
			Assert.AreEqual (1, c.Count, "T2");

			i = new ListItem("This is item 2", "20");
			c.Add(i);
			Assert.AreEqual (2, c.Count, "T3");

			Assert.AreEqual (null, c.FindByText(" is "), "T4");
			Assert.AreEqual (i.Text, c.FindByText("This is item 2").Text, "T5");
			Assert.AreSame (i, c.FindByText("This is item 2"), "T6");
			Assert.AreEqual (1, c.IndexOf(c.FindByText("This is item 2")), "T7");
			Assert.AreEqual (1, c.IndexOf(c.FindByValue("20")), "T8");

			i = new ListItem("Item 3", "30");
			Assert.IsFalse(c.Contains(i), "T9");
			c.Add(i);
			Assert.IsTrue(c.Contains(i), "T10");

			i = new ListItem("Forth", "40");
			i2 = new ListItem("Fifth", "50");
			c.AddRange(new ListItem[] {i, i2});
			Assert.AreEqual (5, c.Count, "T11");

			c.RemoveAt(1);
			Assert.AreEqual (4, c.Count, "T12");
			Assert.AreEqual (null, c.FindByText("This is item 2"), "T13");

			c.Clear();
			Assert.AreEqual (0, c.Count, "T13");
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:40,代碼來源:ListItemCollectionTest.cs

示例2: ContainsTest

		public void ContainsTest ()
		{
			ListItemCollection	c;
			ListItem		i;
			ListItem		i2;

			c = new ListItemCollection();
			i = new ListItem("Item 1", "1");
			i2 = new ListItem("Item 2", "2");

			c.Add(i);
			c.Add(i2);

			i2 = new ListItem("Item 1", "1");

			// test same vs equal
			Assert.AreEqual (true, c.Contains(i), "C1");
			Assert.AreEqual (true, c.Contains(i2), "C2");
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:19,代碼來源:ListItemCollectionTest.cs

示例3: BuscaUsuario

        protected void BuscaUsuario()
        {
            try
            {
                IUsuarios negocio = new BusinessLogic();
                USUARIO userSesion = Session["userToModify"] as USUARIO;
                USUARIO usuario = negocio.BuscaUsuarioRol(userSesion.NOMBRECOMPLETO);
                lblNombreUsuario.Text = userSesion.NOMBRECOMPLETO;
                List<ROL> roles = Session["Roles"] as List<ROL>;
                ListItemCollection collection = new ListItemCollection();
                ListItem item = null;
                if (usuario == null)
                {
                    collection.Clear();

                    foreach (ListItem valor in rblPerfiles.Items)
                    {
                        item = new ListItem { Text=valor.Text,Value=valor.Value};
                        collection.Add(item);
                    }
                    rblPerfiles.Items.Clear();
                    foreach (ListItem valor in collection)
                        rblPerfiles.Items.Add(valor);
                    throw new Exception("Usuario no encontrado");
                }
                Session.Add("UsuarioBuscado", usuario);
                collection.Clear();
                usuario.ROLUSUARIO.ToList().OrderBy(rol => rol.IDROL).ToList().ForEach(rolSelected =>
                {
                    roles.OrderBy(rol => rol.IDROL).ToList().ForEach(rol =>
                    {
                        if (rol.IDROL == rolSelected.IDROL)
                        {
                            item = new ListItem
                            {
                                Text = rol.DESCRIPCIONROL,
                                Value = rol.IDROL.ToString(),
                                Selected = true
                            };
                        }
                        else
                        {
                            item = new ListItem
                            {
                                Text = rol.DESCRIPCIONROL,
                                Value = rol.IDROL.ToString()
                            };
                        }
                        if(!collection.Contains(item))
                            collection.Add(item);
                    });
                });
                if (collection.Count > 0)
                {
                    rblPerfiles.Items.Clear();
                    foreach (ListItem valor in collection)
                        rblPerfiles.Items.Add(valor);
                }
            }
            catch (Exception ex)
            {
                MostrarError(ex.Message);
            }
        }
開發者ID:ramirobr,項目名稱:DQBase,代碼行數:64,代碼來源:AsignarPerfilUsuario.aspx.cs


注:本文中的System.Web.UI.WebControls.ListItemCollection.Contains方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。