protected void remove( ListBox lb ) { int[] selected = lb.GetSelectedIndices(); foreach( int i in selected ) { lb.Items.RemoveAt( i ); } }
private void getValueListBox(ListBox lb, int videoid, int type) { foreach (int i in lb.GetSelectedIndices()) { VideoModel vm = new VideoModel(); vm.Video_Insert_Option(videoid, Convert.ToInt32(lb.Items[i].Value), type); } }
private void RecorrerControles1(ControlCollection MyControlCollection) { foreach (System.Web.UI.Control MyWebServerControl in MyControlCollection) { string typeOfControl = MyWebServerControl.GetType().Name.ToString(); if (!MyWebServerControl.HasControls() || MyWebServerControl.GetType().Name.ToString() == "CheckBoxList") { string controlName = MyWebServerControl.GetType().Name.ToString(); switch (controlName) { case "TextBox": System.Web.UI.WebControls.TextBox MyWebControlTextBox = (System.Web.UI.WebControls.TextBox)MyWebServerControl; if ((MyWebControlTextBox.Text != "")) { _ControlValues_String.Append((MyWebControlTextBox.ID.ToString() + ("=" + (MyWebControlTextBox.Text + "¦")))); } break; case "CheckBox": System.Web.UI.WebControls.CheckBox MyWebControlCheckbox = (System.Web.UI.WebControls.CheckBox)MyWebServerControl; if (MyWebControlCheckbox.Checked) { _ControlValues_String.Append((MyWebControlCheckbox.ID.ToString() + ("=" + (1 + "¦")))); } else { _ControlValues_String.Append((MyWebControlCheckbox.ID.ToString() + ("=" + (0 + "¦")))); } break; case "RadioButton": System.Web.UI.WebControls.RadioButton MyWebControlRadioButton = (System.Web.UI.WebControls.RadioButton)MyWebServerControl; if (MyWebControlRadioButton.Checked) { _ControlValues_String.Append((MyWebControlRadioButton.ID.ToString() + ("=" + (1 + "¦")))); } else { _ControlValues_String.Append((MyWebControlRadioButton.ID.ToString() + ("=" + (0 + "¦")))); } break; case "ListBox": System.Web.UI.WebControls.ListBox MyWebControlListBox = (System.Web.UI.WebControls.ListBox)MyWebServerControl; if ((MyWebControlListBox.SelectedIndex > -1)) { bool bFirstItem = true; foreach (int Index in MyWebControlListBox.GetSelectedIndices()) { if (bFirstItem) { _ControlValues_String.Append((MyWebControlListBox.ID.ToString() + ("=" + MyWebControlListBox.Items[Index].Text))); bFirstItem = false; } else { _ControlValues_String.Append((";" + MyWebControlListBox.Items[Index].Text)); bFirstItem = false; } } if (!bFirstItem) { _ControlValues_String.Append("¦"); } } break; case "CheckBoxList": System.Web.UI.WebControls.CheckBoxList MyWebControlCheckBoxList = (System.Web.UI.WebControls.CheckBoxList)MyWebServerControl; if ((MyWebControlCheckBoxList.SelectedIndex > -1)) { bool bFirstItem = true; for (int i = 0; i < MyWebControlCheckBoxList.Items.Count; i++) { if (MyWebControlCheckBoxList.Items[i].Selected) { if (bFirstItem) { _ControlValues_String.Append((MyWebControlCheckBoxList.ID.ToString() + ("=" + MyWebControlCheckBoxList.Items[i].Text))); bFirstItem = false; } else { _ControlValues_String.Append((";" + MyWebControlCheckBoxList.Items[i].Text)); bFirstItem = false; } } } if (!bFirstItem) { _ControlValues_String.Append("¦"); } } break; case "DropDownList": System.Web.UI.WebControls.DropDownList MyWebControlDropDownList = (System.Web.UI.WebControls.DropDownList)MyWebServerControl; // nuestra convenci�n es que un DropDownList cuyo valor // seleccionado es -1, 'no est� seleccionado'. La raz�n de // esto es que en Asp.Net un DropDownList SIEMPRE est� // seleccionado (!). if (((MyWebControlDropDownList.SelectedIndex > -1) && (((string)(MyWebControlDropDownList.SelectedItem.Value)) != "-1"))) { _ControlValues_String.Append((MyWebControlDropDownList.ID.ToString() + ("=" + (MyWebControlDropDownList.SelectedValue + "¦")))); } break; } } else { // en el control collection vienen Panels y web controls que // a su vez, contienen controls. RecorrerControles0(MyWebServerControl.Controls); } } }
private void getValueListBox(ListBox lb, int roleID) { foreach (int i in lb.GetSelectedIndices()) { RoleModel RL = new RoleModel(); RL.Role_AddLink(roleID, Convert.ToInt32(lb.Items[i].Value)); } }
/// <summary> /// Gets list of all selected items of a listbox /// </summary> /// <param name="listBox">Listbox control</param> /// <returns>Array of selected items</returns> private string[] GetSelectedLstBxValues(ListBox listBox) { int[] arrSelectedIndex = listBox.GetSelectedIndices(); string[] arrValues = new string[arrSelectedIndex.Length]; int counter = 0; foreach (int index in arrSelectedIndex) { arrValues[counter] = listBox.Items[index].Text; counter++; } return arrValues; }
/// <summary> /// Moves spare part items from source list box to destination list box. /// </summary> /// <param name="srcListBox">Source list box to be specified</param> /// <param name="destListBox">Destination list box to be specified</param> /// <param name="srcPriceCalculation">True - adds prices of selected spare parts, false - doesn't add prices of selected spare parts</param> /// <param name="persister">Persister to be specified</param> /// <param name="totalPrice">Stores total price of selected spare parts</param> public static void MoveListItems(ListBox srcListBox, ListBox destListBox, bool srcPriceCalculation, ICarServicePersister persister, out decimal totalPrice) { totalPrice = 0M; int[] srcSelectedIndices = srcListBox.GetSelectedIndices(); ListItemCollection destListItems = destListBox.Items; int totalNumberOfDestItems = destListItems.Count + srcSelectedIndices.Length; List<int> destItemValues = new List<int>(totalNumberOfDestItems); foreach (ListItem item in destListItems) { CarServiceUtility.AddEntityId(destItemValues, item.Value); } foreach (int selectedIndex in srcSelectedIndices) { ListItem item = srcListBox.Items[selectedIndex]; CarServiceUtility.AddEntityId(destItemValues, item.Value); } BindSparePartsLists(destItemValues, srcListBox, destListBox, srcPriceCalculation, persister, out totalPrice); }