Beispiel #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");
        }
Beispiel #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;
    }
Beispiel #3
0
    /// <summary>
    /// Populates the Status list, adds missing items if not contained in the Target Status picklist, and set the selected value.
    /// </summary>
    /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param>
    private void LoadTargetStatusItems(GridViewRowEventArgs e, TargetView target)
    {
        DropDownList statusList = e.Row.FindControl("ddlTargetStatus") as DropDownList;

        statusList.Attributes.Add("onChange", string.Format("javascript:onStatusChange('{0}', '{1}', '{2}', '{3}');",
                                                            statusList.ClientID, txtNewStatusValue.ClientID, cmdStatusChange.ClientID, target.TargetId));
        ListItemCollection listItems = new ListItemCollection();

        foreach (ListItem item in lbxStatus.Items)
        {
            listItems.Add(item);
        }
        if (target != null)
        {
            String   value = target.Status;
            ListItem item  = listItems.FindByText(value);
            if (item == null)
            {
                item = new ListItem {
                    Text = value
                };
                listItems.Add(item);
            }
            statusList.DataSource    = listItems;
            statusList.SelectedValue = value;
        }
    }
Beispiel #4
0
        protected void GetGroup_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListItemCollection listc = GetGroup.Items;
            ListItem           list  = listc.FindByText(GetGroup.Text.Trim());

            CategoryIdList.DataSource     = GetCategory(GetGroup.Text.Trim());
            CategoryIdList.DataTextField  = "CategoryName";
            CategoryIdList.DataValueField = "CategoryID";
            CategoryIdList.DataBind();
        }
  }//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()
 //--------------------------------------------------------
 /// <summary>Selects a list item given the display value</summary>
 /// <returns>True if value was located and selected</returns>
 public static bool SelectItemByText(ListItemCollection list, string text)
 {
     try
     {
         list.FindByText(text).Selected = true;
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #7
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");
        }
Beispiel #8
0
        public void AddTest()
        {
            ListItemCollection c;
            ListItem           i;

            c = new ListItemCollection();

            c.Add("string");

            Assert.AreEqual("string", c.FindByText("string").ToString(), "A1");

            c.Add((string)null);
            c.Add((ListItem)null);
            Assert.AreEqual(3, c.Count, "A2");
        }
Beispiel #9
0
        public void AssignmentTest()
        {
            ListItemCollection c;
            ListItem           i;

            c = new ListItemCollection();
            i = new ListItem("Text", "Value");

            c.Add(i);

            i             = new ListItem("Blah", "Argl");
            ((IList)c)[0] = i;

            Assert.AreEqual("Blah", c.FindByText("Blah").ToString(), "AS1");
            Assert.AreEqual(1, c.Count, "AS2");
        }
Beispiel #10
0
        public Boolean SelectListItem(ListItemCollection ListCollection, String ItemSelect)
        {
            if (ListCollection == null)
            {
                return(false);
            }

            ListItem Item = ListCollection.FindByText(ItemSelect);

            if (Item != null)
            {
                Item.Selected = true;
                return(true);
            }

            return(false);
        }
    /// <summary>
    /// Populates the Status list, adds missing items if not contained in the Target Status picklist, and set the selected value.
    /// </summary>
    /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param>
    private void LoadTargetStatusItems(GridViewRowEventArgs e, TargetView target)
    {
        DropDownList       statusList = e.Row.FindControl("ddlTargetStatus") as DropDownList;
        ListItemCollection listItems  = new ListItemCollection();

        foreach (ListItem item in lbxStatus.Items)
        {
            listItems.Add(item);
        }
        if (target != null)
        {
            String   value = target.Status;
            ListItem item  = listItems.FindByText(value);
            if (item == null)
            {
                item = new ListItem {
                    Text = value
                };
                listItems.Add(item);
            }
            statusList.DataSource    = listItems;
            statusList.SelectedValue = value;
        }
    }
Beispiel #12
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;
    }
 /// <summary>
 /// Populates the Status list, adds missing items if not contained in the Target Status picklist, and set the selected value.
 /// </summary>
 /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param>
 private void LoadTargetStatusItems(GridViewRowEventArgs e, TargetView target)
 {
     DropDownList statusList = e.Row.FindControl("ddlTargetStatus") as DropDownList;
     statusList.Attributes.Add("onChange", string.Format("javascript:onStatusChange('{0}', '{1}', '{2}', '{3}');",
         statusList.ClientID, txtNewStatusValue.ClientID, cmdStatusChange.ClientID, target.TargetId));
     ListItemCollection listItems = new ListItemCollection();
     foreach (ListItem item in lbxStatus.Items)
         listItems.Add(item);
     if (target != null)
     {
         String value = target.Status;
         ListItem item = listItems.FindByText(value);
         if (item == null)
         {
             item = new ListItem {Text = value};
             listItems.Add(item);
         }
         statusList.DataSource = listItems;
         statusList.SelectedValue = value;
     }
 }
Beispiel #14
0
        /// <summary>
        /// Method will loop through the literal controls inside the repeater.
        /// Assign the id value if found the duplicate items
        /// </summary>
        /// <param name="ids">Name of the literal controls who has duplicate values</param>
        public virtual void InitializeDuplicateItems(ArrayList ids)
        {
            if (ids.Count == 0)
            {
                return;
            }

            ArrayList          listOfDups = new ArrayList();
            ListItemCollection itemsList  = new ListItemCollection();
            int index = 0;

            if (ids.Count == 1)
            {
                System.Web.UI.WebControls.Repeater rep = (System.Web.UI.WebControls.Repeater)(BaseClasses.Utils.MiscUtils.FindControlRecursively(this as BaseApplicationTableControl, this.RepeaterName));
                foreach (System.Web.UI.WebControls.RepeaterItem repItem in rep.Items)
                {
                    PrimaryKeyRecord             pkRecord   = ((PrimaryKeyRecord)(this._DataSource[index]));
                    BaseApplicationRecordControl recControl = (BaseApplicationRecordControl)(repItem.FindControl(this.RowName));
                    foreach (System.Web.UI.Control ctrlItem in recControl.Controls)
                    {
                        Literal    ltlCtrl;
                        Label      lblCtrl;
                        LinkButton lbtnCtrl;
                        string     txtValue = "";
                        if (ctrlItem.ID == ids[0].ToString())
                        {
                            if (ctrlItem is System.Web.UI.WebControls.Literal)
                            {
                                ltlCtrl  = (System.Web.UI.WebControls.Literal)(ctrlItem);
                                txtValue = ltlCtrl.Text;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.Label)
                            {
                                lblCtrl  = (System.Web.UI.WebControls.Label)(ctrlItem);
                                txtValue = lblCtrl.Text;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.LinkButton)
                            {
                                lbtnCtrl = (System.Web.UI.WebControls.LinkButton)(ctrlItem);
                                txtValue = lbtnCtrl.Text;
                            }

                            if (txtValue != "")
                            {
                                ListItem dupItem = itemsList.FindByText(txtValue);
                                if (dupItem != null)
                                {
                                    listOfDups.Add(dupItem.Text);
                                    dupItem.Text = dupItem.Text + " (ID " + dupItem.Value + ")";
                                }

                                ListItem newItem = new ListItem(txtValue, pkRecord.GetID().ToDisplayString());
                                itemsList.Add(newItem);

                                if (listOfDups.Contains(newItem.Text))
                                {
                                    newItem.Text = newItem.Text + " (ID " + newItem.Value + ")";
                                }
                                break;
                            }
                        }
                    }
                    index++;
                }

                index = 0;
                foreach (System.Web.UI.WebControls.RepeaterItem repItem in rep.Items)
                {
                    BaseApplicationRecordControl recControl = (BaseApplicationRecordControl)(repItem.FindControl(this.RowName));
                    foreach (System.Web.UI.Control ctrlItem in recControl.Controls)
                    {
                        if (ctrlItem.ID == ids[0].ToString())
                        {
                            if (ctrlItem is System.Web.UI.WebControls.Literal && itemsList.Count != 0)
                            {
                                Literal ltCtrl = (System.Web.UI.WebControls.Literal)(ctrlItem);
                                ltCtrl.Text = itemsList[index].Text;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.Label && itemsList.Count != 0)
                            {
                                Label ltCtrl = (System.Web.UI.WebControls.Label)(ctrlItem);
                                ltCtrl.Text = itemsList[index].Text;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.LinkButton && itemsList.Count != 0)
                            {
                                LinkButton ltCtrl = (System.Web.UI.WebControls.LinkButton)(ctrlItem);
                                ltCtrl.Text = itemsList[index].Text;
                            }
                        }
                    }
                    index++;
                }
            }
            else if (ids.Count == 2)
            {
                System.Web.UI.WebControls.Repeater rep = (System.Web.UI.WebControls.Repeater)(BaseClasses.Utils.MiscUtils.FindControlRecursively(this as BaseApplicationTableControl, this.RepeaterName));
                foreach (System.Web.UI.WebControls.RepeaterItem repItem in rep.Items)
                {
                    int                          count      = 0;
                    string                       ltText     = "";
                    PrimaryKeyRecord             pkRecord   = ((PrimaryKeyRecord)(this._DataSource[index]));
                    BaseApplicationRecordControl recControl = (BaseApplicationRecordControl)(repItem.FindControl(this.RowName));
                    foreach (System.Web.UI.Control ctrlItem in recControl.Controls)
                    {
                        if (ctrlItem.ID == ids[0].ToString() || ctrlItem.ID == ids[1].ToString())
                        {
                            if (ctrlItem is System.Web.UI.WebControls.Literal)
                            {
                                Literal ltCtrl = (System.Web.UI.WebControls.Literal)(ctrlItem);
                                ltText += ltCtrl.Text;

                                count++;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.Label)
                            {
                                Label ltCtrl = (System.Web.UI.WebControls.Label)(ctrlItem);
                                ltText += ltCtrl.Text;

                                count++;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.LinkButton)
                            {
                                LinkButton ltCtrl = (System.Web.UI.WebControls.LinkButton)(ctrlItem);
                                ltText += ltCtrl.Text;

                                count++;
                            }
                        }

                        if (count == ids.Count)
                        {
                            ListItem dupItem = itemsList.FindByText(ltText);
                            if (dupItem != null)
                            {
                                listOfDups.Add(dupItem.Text);
                                dupItem.Text = " (ID " + dupItem.Value + ")";
                            }

                            ListItem newItem = new ListItem(ltText, pkRecord.GetID().ToDisplayString());
                            itemsList.Add(newItem);

                            if (listOfDups.Contains(newItem.Text))
                            {
                                newItem.Text = " (ID " + newItem.Value + ")";
                            }
                            break;
                        }
                    }
                    index++;
                }

                index = 0;
                foreach (System.Web.UI.WebControls.RepeaterItem repItem in rep.Items)
                {
                    BaseApplicationRecordControl recControl = (BaseApplicationRecordControl)(repItem.FindControl(this.RowName));
                    foreach (System.Web.UI.Control ctrlItem in recControl.Controls)
                    {
                        if ((ctrlItem.ID == ids[0].ToString() || ctrlItem.ID == ids[1].ToString()) && itemsList.Count != 0)
                        {
                            if (ctrlItem is System.Web.UI.WebControls.Literal && itemsList[index].Text.Contains(" (ID "))
                            {
                                Literal ltCtrl = (System.Web.UI.WebControls.Literal)(ctrlItem);
                                ltCtrl.Text = ltCtrl.Text + itemsList[index].Text;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.Label && itemsList[index].Text.Contains(" (ID "))
                            {
                                Label ltCtrl = (System.Web.UI.WebControls.Label)(ctrlItem);
                                ltCtrl.Text = ltCtrl.Text + itemsList[index].Text;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.LinkButton && itemsList[index].Text.Contains(" (ID "))
                            {
                                LinkButton ltCtrl = (System.Web.UI.WebControls.LinkButton)(ctrlItem);
                                ltCtrl.Text = ltCtrl.Text + itemsList[index].Text;
                            }
                        }
                    }
                    index++;
                }
            }
        }
Beispiel #15
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            var fields = new ListItemCollection();

            fields = cblAutomatic.Items;

            // Read selected fields
            // Quirk Alert: if we have disabled an item from javascript, it can't be read here on postback.
            // Instead we have to cycle a hidden checkboxlist that contains resource fileds IF chkResource is checked
            foreach (ListItem field in cblFields.Items)
            {
                if (field.Selected && fields.FindByText(field.Text) == null)
                {
                    fields.Add(field);
                }
            }

            // Add all resource fields if chkResource is checked.
            // (Only add if not already in the list)
            if (chkResource.Checked)
            {
                foreach (ListItem resourceField in cblResources.Items)
                {
                    if (fields.FindByText(resourceField.Text) == null)
                    {
                        fields.Add(resourceField);
                    }
                }
            }

            var rb = new EPMLiveCore.ReportHelper.ReportBiz(SPContext.Current.Site.ID);

            if (_existing)
            {
                EPMLiveCore.ReportHelper.ListBiz lb = rb.GetListBiz(_existingListId);
                lb.UpdateListMapping(fields);
            }
            else
            {
                var listId = new Guid(ddlLists.SelectedValue);
                rb.CreateListBiz(listId, fields);
            }

            try
            {
                //FOREIGN IMPLEMENTATION -- START
                var DAO = new EPMLiveCore.ReportHelper.EPMData(SPContext.Current.Site.ID);
                rb.UpdateForeignKeys(DAO);
                DAO.Dispose();
                // -- END
            }
            catch (Exception ex)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    if (!EventLog.SourceExists("EPMLive Reporting - UpdateForeignKeys"))
                    {
                        EventLog.CreateEventSource("EPMLive Reporting - UpdateForeignKeys", "EPM Live");
                    }

                    var myLog = new EventLog("EPM Live", ".", "EPMLive Reporting - UpdateForeignKeys");
                    myLog.MaximumKilobytes = 32768;
                    myLog.WriteEntry(ex.Message + ex.StackTrace, EventLogEntryType.Error, 4001);
                });
            }

            SPUtility.Redirect("epmlive/ListMappings.aspx", SPRedirectFlags.RelativeToLayoutsPage, HttpContext.Current);
        }