Exemplo n.º 1
0
        public void ViewState()
        {
            ListItemCollection c;
            ListItemCollection c2;
            ListItem           i;
            ListItem           i2;
            object             state;

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

            ((IStateManager)c).TrackViewState();

            c.Add(i);
            c.Add(i2);
            Assert.AreEqual(2, c.Count, "V1");

            state = ((IStateManager)c).SaveViewState();

            c2 = new ListItemCollection();
            ((IStateManager)c2).LoadViewState(state);
            Assert.AreEqual(2, c2.Count, "V2");
            Assert.AreEqual("Item 1", c2.FindByText("Item 1").ToString(), "V3");
            Assert.AreEqual("Item 2", c2.FindByText("Item 2").ToString(), "V4");
            Assert.AreEqual(false, c2.IndexOf(i) == c2.IndexOf(i2), "V5");
        }
Exemplo n.º 2
0
    /// <summary>
    /// 在UI控件呈现之前,将DropDownList控件的选择项设为指定的模式。
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_PreRender(object sender, EventArgs e)
    {
        ListItemCollection items = DisplayModeDropdown.Items;
        int selectedIndex        = items.IndexOf(items.FindByText(_manager.DisplayMode.Name));

        DisplayModeDropdown.SelectedIndex = selectedIndex;
    }
Exemplo n.º 3
0
        public ListItemCollection GetMonth2(string selecteditem)
        {
            ListItemCollection lst = new ListItemCollection();

            lst = GetMonth();
            lst.IndexOf(lst.FindByValue(selecteditem));
            return(lst);
        }
  }//void DropDownListDisplayMode_SelectedIndexChanged()

  /// <summary>Page_PreRender</summary>
  /// <remarks>Set the selected item equal to the current display mode.</remarks>
  public void Page_PreRender
  (
   object sender, 
   EventArgs e
  )
  {
   ListItemCollection items = DropDownListDisplayMode.Items;
   int selectedIndex = items.IndexOf(items.FindByText(webPartManager.DisplayMode.Name));
   DropDownListDisplayMode.SelectedIndex = selectedIndex;
  }//void Page_PreRender()
Exemplo n.º 5
0
        public void IndexOfTest()
        {
            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);

            i = new ListItem("Item 2", "2");

            // test same vs equal
            Assert.AreEqual(1, c.IndexOf(i), "IO1");
            Assert.AreEqual(1, c.IndexOf(i2), "IO2");
        }
Exemplo n.º 6
0
        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");
        }
Exemplo n.º 7
0
    protected void GenerateModeList(object sender, EventArgs e)
    {
        WebPartManager _manager        = WebPartManager.GetCurrentWebPartManager(Page);
        String         browserModeName = WebPartManager.BrowseDisplayMode.Name;

        DropDownListModes.Items.Clear();

        // Fill the drop-down list with the names of supported display modes
        foreach (WebPartDisplayMode mode in _manager.SupportedDisplayModes)
        {
            String modeName = mode.Name;
            if (mode.IsEnabled(_manager))
            {
                ListItem item = new ListItem(modeName, modeName);
                DropDownListModes.Items.Add(item);
            }
        }

        // Select current mode
        ListItemCollection items = DropDownListModes.Items;
        int selectedIndex        = items.IndexOf(items.FindByText(_manager.DisplayMode.Name));

        DropDownListModes.SelectedIndex = selectedIndex;
    }