public string GetListBoxItems(System.Web.UI.WebControls.ListBox lst) { string s = ""; try { foreach (ListItem li in lst.Items) { // If 'All' (no value) is detected, return s == "" (indicating all) if (li.Selected && li.Value.Length == 0) { throw(new ArgumentNullException()); } else if (li.Selected) { s += li.Value.ToString() + ","; } } s = s.TrimEnd(','); } catch { s = ""; } return(s); }
/// <summary> /// Adds end-scores of a played match the database when all fields have been filled in correctly /// or else a error message is shown. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAddDetailsConfirm_Click(object sender, EventArgs e) { System.Web.UI.WebControls.ListBox MatchChoice = (System.Web.UI.WebControls.ListBox)ucMatchesOnDateDetails.FindControl("lbMatches"); DatePicker dpDate = (DatePicker)ucMatchesOnDateDetails.FindControl("dpMatchPick"); List <Match> Matches = db.GetMatches(dpDate.SelectedDate); int HomeScore = Convert.ToInt32(tbHomeScore.Text); int AwayScore = Convert.ToInt32(tbAwayScore.Text); if (int.TryParse(tbHomeScore.Text, out HomeScore) && int.TryParse(tbAwayScore.Text, out AwayScore) && HomeScore != AwayScore) { string Topscorer = ddlTopscorer.SelectedValue; foreach (Match m in Matches) { if (m.ToString() == MatchChoice.SelectedItem.ToString()) { Match ChosenMatch = m; if (ChosenMatch.AddDetails(HomeScore, AwayScore, Topscorer)) { lblError.Visible = false; break; } } } } else { lblError.Visible = true; } }
protected override void CreateChildControls() { CustomersList = new ListBox(); CustomersList.Rows = 4; Controls.Add(CustomersList); }
private void Page_Load(object sender, System.EventArgs e) { HtmlForm frm = (HtmlForm)FindControl("Form1"); GHTTestBegin(frm); foreach (Type currentType in TestedTypes) ListControl_ClearSelection(currentType); // Clearing multiple selected items: // This cannot be tested in ListControl, because only ListBox can have multiple selection. GHTSubTestBegin("Clear multiple selection"); System.Web.UI.WebControls.ListBox lb = new System.Web.UI.WebControls.ListBox(); GHTActiveSubTest.Controls.Add(lb); try { lb.Items.Add("A"); lb.Items.Add("B"); lb.Items.Add("C"); lb.Items.Add("D"); lb.SelectionMode = ListSelectionMode.Multiple; lb.Items[0].Selected = true; lb.Items[1].Selected = true; lb.Items[2].Selected = true; lb.ClearSelection(); } catch (Exception ex) { GHTSubTestUnexpectedExceptionCaught(ex); } GHTSubTestEnd(); GHTTestEnd(); }
public void BindList(System.Web.UI.WebControls.ListBox theListBox, DataTable theDT, string theTextField, string theValueField) { theListBox.DataSource = theDT; theListBox.DataTextField = theTextField; theListBox.DataValueField = theValueField; theListBox.DataBind(); }
public static bool SelectListText(System.Web.UI.WebControls.ListBox lst, string[] textList) { bool status = true; bool found = false; for (int i = 0; i < lst.Items.Count; i++) { lst.Items[i].Selected = false; } foreach (string text in textList) { found = false; foreach (System.Web.UI.WebControls.ListItem item in lst.Items) { if (item.Text == text) { item.Selected = true; found = true; } } // Any text not found in the list, are added to the list and // this resets the status. if (!found && text.Length > 0) { lst.Items.Add(text); lst.Items[lst.Items.Count - 1].Selected = true; status = false; } } return(status); }
public McmsWebQuestion(string strId, bool bRequired, string strRequiredText, string strQuestion, string strControlBase, RepeatDirection rdLayout, string[] strResponses) : base(strId, "mcms", bRequired, strRequiredText, strQuestion) { this.m_listBox = new ListBox(); this.m_checkBoxList = new CheckBoxList(); this.m_listControl = null; if (strControlBase == "checkbox") { this.m_checkBoxList.RepeatDirection = rdLayout; this.m_listControl = this.m_checkBoxList; } else { this.m_listBox.SelectionMode = ListSelectionMode.Multiple; this.m_listControl = this.m_listBox; } foreach (string text in strResponses) { this.m_listControl.Items.Add(new ListItem(text)); } this.m_listControl.ID = "lst_" + strId; this.Controls.Add(this.m_listControl); if (bRequired) { ListControlValidator child = new ListControlValidator(); child.EnableClientScript = false; child.Text = strRequiredText; child.Display = ValidatorDisplay.Dynamic; child.ControlToValidate = this.m_listControl.ID; this.Controls.Add(child); } this.Controls.Add(new LiteralControl("</p>")); }
private void SortListBox(ListBox list_box) { ArrayList ListBoxArray = new ArrayList(); int i = 0; while (i < list_box.Items.Count) { ListBoxArray.Add(list_box.Items[i].Text); ++i; } list_box.Items.Clear(); ListBoxArray.Sort(); i = 0; while (ListBoxArray.Count > i) { list_box.Items.Add(ListBoxArray[i].ToString()); ++i; } }
private void _loadTemplates(ListBox list, string scriptType) { string path = IO.SystemDirectories.Umbraco + "/scripting/templates/" + scriptType + "/"; string abPath = IO.IOHelper.MapPath(path); list.Items.Clear(); // always add the option of an empty one list.Items.Add(scriptType == "cshtml" ? new ListItem("Empty template", "cshtml/EmptyTemplate.cshtml") : new ListItem("Empty template", "")); if (System.IO.Directory.Exists(abPath)) { string extension = "." + scriptType; //Already adding Empty Template as the first item, so don't add it again foreach (System.IO.FileInfo fi in new System.IO.DirectoryInfo(abPath).GetFiles("*" + extension).Where(fi => fi.Name != "EmptyTemplate.cshtml")) { string filename = System.IO.Path.GetFileName(fi.FullName); var liText = filename.Replace(extension, "").SplitPascalCasing().ToFirstUpperInvariant(); list.Items.Add(new ListItem(liText, scriptType + "/" + filename)); } } }
protected override void CreateChildControls() { if (this.Field != null && this.ControlMode != SPControlMode.Display) { if (!this.ChildControlsCreated) { CustomDropDownList field = this.Field as CustomDropDownList; base.CreateChildControls(); /* MultiLookupPicker = (GroupedItemPicker)TemplateContainer.FindControl("MultiLookupPicker"); BuildAvailableItems(ref MultiLookupPicker); SelectCandidate = (SPHtmlSelect)TemplateContainer.FindControl("SelectCandidate"); SelectResult = (SPHtmlSelect)TemplateContainer.FindControl("SelectResult"); AddButton = (HtmlButton)TemplateContainer.FindControl("AddButton"); RemoveButton = (HtmlButton)TemplateContainer.FindControl("RemoveButton"); */ left_box = (ListBox)TemplateContainer.FindControl("LeftBox"); if (left_box.Attributes["done"] == null) { BuildAvailableItems(ref left_box); } right_box = (ListBox)TemplateContainer.FindControl("RightBox"); add_button = (Button)TemplateContainer.FindControl("AddButton"); add_button.Click += new EventHandler(add_button_Click); remove_button = (Button)TemplateContainer.FindControl("RemoveButton"); remove_button.Click += new EventHandler(remove_button_Click); } } }
public void CarregarListas(ListBox listaTodos, ListBox listaAdicionados) { try { this.listaTodos = new ListBox(); foreach (ListItem item in listaTodos.Items) { lstListaTodos.Items.Add(new ListItem(item.Text, item.Value)); this.listaTodos.Items.Add(new ListItem(item.Text, item.Value)); } foreach (ListItem item in listaAdicionados.Items) lstListaAdicionados.Items.Add(new ListItem(item.Text, item.Value)); ExcluirItensIguais(); OrdenarLista(lstListaTodos); OrdenarLista(lstListaAdicionados); } catch (Exception) { throw; } }
/// <summary> /// 设置 下拉列表的值 用,号隔开 /// </summary> /// <param name="cblControls"></param> /// <param name="strValue"></param> public static void SetGetListBoxSelectValue(System.Web.UI.WebControls.ListBox cblControls, string strValue, string strParam) { //string[] strValues = Utils.strSplit(strValue, strParam); //ListItem lItem = null; //for(int i=0;i<cblControls.Items.Count;i++) //循环控件项 //{ // lItem = cblControls.Items[i]; // for(int j=0;j<strValue.Length;j++) // { // if (lItem.Value == strValues[j]) //如果当前控件项和要绑定的值相等 则绑定 退出此次小循环 // { // lItem.Selected = true; // break; // } // } //} string[] arrStrValue; arrStrValue = Utils.strSplit(strValue, strParam); foreach (string strItem in arrStrValue) { foreach (ListItem item in cblControls.Items) { if (item.Value == strItem) { item.Selected = true; break; } } } }
public static void SelectListItem(ListBox listbox, string selectedValue) { bool foundListItem = false; foreach (ListItem item in listbox.Items) { if (item.Value == selectedValue) { foundListItem = true; item.Selected = true; } else { item.Selected = false; } } if (foundListItem == false) { ListItem item = new ListItem(selectedValue, selectedValue); item.Selected = true; listbox.Items.Add(item); } }
public void AddInfo(TextBox txtBox, ListBox listBox, AddDelegate addMethod, GetDelegate getMethod) { string txt = txtBox.Text; int addCount = 0; DataSet ds; if (txt != "") { addCount = addMethod(txt); if (addCount <= 0) { MsgBox("该值已存在!"); } } else { MsgBox("不能添加空值!"); } listBox.Items.Clear(); txtBox.Text = ""; ds = getMethod(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { listBox.Items.Add(ds.Tables[0].Rows[i][0].ToString()); } txtBox.Focus(); }
//所有权限 private void CreatelstAccount(ListBox listcontrol, int PermissionCategoryId) { Johnny.CMS.BLL.Access.Permission bll = new Johnny.CMS.BLL.Access.Permission(); listcontrol.DataSource = bll.GetList(PermissionCategoryId); listcontrol.DataTextField = "PermissionName"; listcontrol.DataValueField = "PermissionId"; listcontrol.DataBind(); }
//所有菜单栏目 private void CreateAllItems(ListBox listcontrolleft) { Johnny.CMS.BLL.SystemInfo.MenuCategory bll = new Johnny.CMS.BLL.SystemInfo.MenuCategory(); listcontrolleft.DataSource = bll.GetList(); listcontrolleft.DataTextField = "MenuCategoryName"; listcontrolleft.DataValueField = "MenuCategoryId"; listcontrolleft.DataBind(); }
public void ListBindToData(ListBox lb, DataTable dt, string dataTextField, string dataValueField) { lb.Items.Clear(); lb.DataSource = dt; lb.DataTextField = dataTextField; lb.DataValueField = dataValueField; lb.DataBind(); }
public static void PopulateListBoxFromDelimitedString(ListBox listBox, String s) { foreach (var item in s.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) { var parts = item.Split(",".ToCharArray()); listBox.Items.Add(new ListItem(parts[0], parts[1])); } }
public static String GetListBoxItemsAsDelimitedString(ListBox listBox) { return listBox.Items .Cast<ListItem>() .Select(li => li.Text + "," + li.Value) .Join(";"); }
/// <summary> /// Initializes a new instance of the <see cref="Adf.Web.UI.DropDownListItem"/> class with the specified label and drop-down list. /// </summary> /// <param name="label">The <see cref="System.Web.UI.WebControls.Label"/> that defines display text of the drop-down list within <see cref="Adf.Web.UI.BasePanelItem"/>.</param> /// <param name="listBox">The <see cref="System.Web.UI.WebControls.DropDownList"/> that defines the control which will be added into <see cref="Adf.Web.UI.BasePanelItem"/>.</param> public ListBoxItem(Label label, ListBox listBox) { ListBox = listBox; _labelControls.Add(label); _itemControls.Add(listBox); }
private static void SelectNextAvailableItemInListBox(ListBox listBox, Int32 previousSelectedIndex) { if (listBox.Items.Count == 0) return; else if (listBox.Items.Count == previousSelectedIndex) listBox.SelectedIndex = listBox.Items.Count - 1; else listBox.SelectedIndex = previousSelectedIndex; }
public string[] getListBoxItems(ListBox lb_covit) { string[] arr = new string[lb_covit.Items.Count]; for (int i = 0; i < lb_covit.Items.Count; i++) { arr[i] = lb_covit.Items[i].ToString(); } return arr; }
public static List<int> GetValueListInt(System.Web.UI.WebControls.ListBox lb) { List<int> selectedItems = new List<int>(); foreach (System.Web.UI.WebControls.ListItem li in lb.Items) { selectedItems.Add(int.Parse(li.Value)); } return selectedItems; }
public void TextArray() { var lb = new ListBox(); lb.Items.Add("abc"); lb.Items.Add("def"); var arr = lb.GetTextsArray(); Assert.AreEqual(arr.Length, 2); }
/// <summary> /// Create a <see cref="System.Web.UI.WebControls.DropDownList"/> and add it into <see cref="Adf.Web.UI.BasePanelItem"/>. /// </summary> /// <param name="label">The display text of the drop-down list within <see cref="Adf.Web.UI.BasePanelItem"/>.</param> /// <param name="name">Set the identification of <see cref="System.Web.UI.WebControls.DropDownList"/> control.</param> /// <param name="width">Width of <see cref="System.Web.UI.WebControls.DropDownList"/> control.</param> /// <param name="enabled">A value indicating whether the <see cref="System.Web.UI.WebControls.DropDownList"/> control is enabled or not.</param> /// <returns>A new instance of the <see cref="Adf.Web.UI.DropDownListItem"/> class.</returns> public static ListBoxItem Create(string label, string name, int width, bool enabled = true, ListSelectionMode mode = ListSelectionMode.Single) { var l = new Label {Text = ResourceManager.GetString(label)}; var list = new ListBox { ID = Prefix + name, Enabled = enabled, Width = new Unit(width, UnitType.Ex), SelectionMode = mode }; list.PreRender += delegate { list.CssClass = (list.Enabled) ? ("DropDownList") : ("DropDownList ReadOnly"); }; return new ListBoxItem(l, list); }
protected string[] GetSelected(ListBox lb) { var strArr = ""; foreach(ListItem li in lb.Items) { if(li.Selected) strArr+=li.Value + ","; } return strArr.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); }
private void BindLocationList(System.Web.UI.WebControls.ListBox locationListBox) { locationListBox.DataSource = Sites; locationListBox.DataTextField = "Name"; locationListBox.DataValueField = "Id"; locationListBox.DataBind(); locationListBox.Items.Insert(0, new ListItem(AllLocationsLabel, AllIndex)); locationListBox.Items.Insert(1, new ListItem("", "-1")); }
private void BindGroupList(System.Web.UI.WebControls.ListBox groupListBox) { groupListBox.DataSource = PersonTypes; groupListBox.DataTextField = "Name"; groupListBox.DataValueField = "Id"; groupListBox.DataBind(); groupListBox.Items.Insert(0, new ListItem(AllGroupsLabel, AllIndex)); groupListBox.Items.Insert(1, new ListItem("", "-1")); }
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)); } }
private void MoveBetween(ListBox from, ListBox to) { while(from.SelectedItem != null) { ListItem selected = from.SelectedItem; from.Items.Remove(selected); to.Items.Add(selected); } }
public static void MoveAllItemsToListBox(ListBox sourceListBox, ListBox destinationListBox) { if (sourceListBox.Items.Count == 0) return; destinationListBox.SelectedIndex = -1; var a = new ListItem[sourceListBox.Items.Count]; sourceListBox.Items.CopyTo(a, 0); destinationListBox.Items.AddRange((ListItem[]) a); sourceListBox.Items.Clear(); }
protected void repassaExame(ref ListBox origem, ref ListBox destino) { if (origem.SelectedIndex > -1) { ListItem item = origem.SelectedItem; destino.Items.Add(item); destino.SelectedIndex = -1; origem.Items.Remove(item); OrdenarLista(ref destino); } }
public static void ListBox_AppendItem(ListBox lstBox, DataTable dt, string textFieldName, string valueFieldName) { string strText; string strValue; foreach (DataRow dr in dt.Rows) { strText = dr[textFieldName].ToString(); strValue = dr[valueFieldName].ToString(); ListItem item = new ListItem(strText, strValue); lstBox.Items.Add(item); } }
// Constructor ////////////////////////////////////////////////////////////////// public PageTemplateSelector() { InputUnitCssClass = "sn-inputunit sn-iu-previewchooser"; _listControl = new ListBox { AutoPostBack = false, SelectionMode = ListSelectionMode.Single, Rows = 10 }; _listControl.Attributes.Add("onchange", GetOnChangeScript(PreviewPicControlId)); LoadPageTemplates(_listControl); }
public TagsRow(TagsEditor table) { this.table = table; AddedList = new ListBox(); TagButton = new Button(); UntagButton = new Button(); AddButton = new Button(); AdditionalBox = new TextBox(); AvailableList = new ListBox(); Label = new Label(); }
public static void ddlSongsFill(ListBox ddlSongs) { var response = SessionState.Client.GetAsync("api/song").Result; if (response.IsSuccessStatusCode) { var songs = response.Content.ReadAsAsync<IEnumerable<Song>>().Result; ddlSongs.DataTextField = "Title"; ddlSongs.DataValueField = "Id"; ddlSongs.DataSource = songs.ToList(); ddlSongs.DataBind(); } }
///// <summary> ///// 判断<see cref="ListBoxEx"/>里是否存在指定的值。 ///// </summary> ///// <param name="listBox">要判断<see cref="ListBoxEx"/>。</param> ///// <param name="itemValue">要检查的值。</param> ///// <returns>是否存在。</returns> //public static bool IsExistedValueInListBox(ListBoxEx listBox, string itemValue) //{ // if (listBox != null && !string.IsNullOrEmpty(itemValue)) // { // foreach (ListItem item in listBox.Items) // { // if (string.Equals(item.Value, itemValue, StringComparison.InvariantCultureIgnoreCase)) // return true; // } // } // return false; //} /// <summary> /// 将源<see cref="ListBox"/> 里的所有的项移到目标<see cref="ListBox"/>里。 /// </summary> /// <param name="source">源<see cref="ListBox"/>。</param> /// <param name="dest">目标<see cref="ListBox"/>。</param> public static void AddAll(ListBox source, ListBox dest) { if (source != null && dest != null) { foreach (ListItem item in source.Items) { if (!dest.Items.Contains(item)) dest.Items.Add(item); } source.Items.Clear(); } }
protected void Page_Load(object sender, EventArgs e) { FormGeneratorData d = new FormGeneratorData(); MasterPage mp = Page.Master; DataTable dtControls = d.GetPageControlsByPageID("1"); foreach (DataRow dr in dtControls.Rows) { string phID = dr["ASP_ID"].ToString(); string type = dr["TypeName"].ToString(); PlaceHolder ph = (PlaceHolder)mp.FindControl(phID); if (type == "TextBox") { TextBox tb = new TextBox(); tb.ID = dr["Unique_ID"].ToString(); tb.CssClass = dr["CssClass"].ToString(); tb.Attributes.Add("placeholder", dr["Placeholder"].ToString()); ph.Controls.Add(tb); } if (type == "ListBox") { ListBox lb = new ListBox(); lb.ID = dr["Unique_ID"].ToString(); lb.CssClass = dr["CssClass"].ToString(); ph.Controls.Add(lb); } else if (type == "DropDownList") { DropDownList ddl = new DropDownList(); ddl.ID = dr["Unique_ID"].ToString(); ddl.CssClass = dr["CssClass"].ToString(); ph.Controls.Add(ddl); } else if (type == "Multi-line") { TextBox tb = new TextBox(); tb.ID = dr["Unique_ID"].ToString(); tb.CssClass = dr["CssClass"].ToString(); tb.TextMode = TextBoxMode.MultiLine; tb.Attributes.Add("placeholder", dr["Placeholder"].ToString()); ph.Controls.Add(tb); } ph.Controls.Add(new LiteralControl("<br />")); } }
//ListBox public void Bind_ListBox(System.Web.UI.WebControls.ListBox MyListBox, string SQL, string DataValueField, string DataTextField) { SqlDataReader dr = SqlHelper.ExecuteReader(SQL); while (dr.Read()) { ListItem theItem = new ListItem(); theItem.Text = dr[DataTextField].ToString(); theItem.Value = dr[DataValueField].ToString(); MyListBox.Items.Add(theItem); } dr.Close(); }
private void AdjustSelectedIndexToBeNotEqual ( System.Web.UI.WebControls.ListBox fixedControl, System.Web.UI.WebControls.ListBox toAlterControl ) { int totalItems = toAlterControl.Items.Count; if (fixedControl.SelectedIndex == toAlterControl.SelectedIndex) { toAlterControl.SelectedIndex = (toAlterControl.SelectedIndex + 1) % totalItems; } }
public void BindDetpLB(System.Web.UI.WebControls.ListBox lb) { DataSet ds = deptdal.getDept(); if (ds != null) { lb.DataSource = ds; lb.DataTextField = "DeptName"; lb.DataValueField = "DeptID"; lb.DataBind(); lb.Items.Insert(0, new ListItem("所有部门", "0")); } }
public void FillListBox(System.Web.UI.WebControls.ListBox lb, TTSHWCFReference.DropDownName listname, string Condition = "") { TTSHWCFServiceClient cl = new TTSHWCFServiceClient(); try { List <TTSHWCFReference.clsDropDown> listbox = cl.GetDropDownData(listname, ddlAuditModules.SelectedValue, "", "", "", "").ToList(); lb.DataSource = listbox; lb.DataTextField = "DisplayField"; lb.DataValueField = "ValueField"; lb.DataBind(); //lb.Items.Insert(0, new ListItem("--Select--", "-1")); } catch { } }
public void FillListBox(System.Web.UI.WebControls.ListBox lst, ref tblAttributes objtblAttr, bool blnAutoPostBack) { SqlDataReader objReader = null; try { FillDataReader obj = new FillDataReader(); DBConnectionOpenDynamic(0); if (objReader != null) { if (objReader.IsClosed == false) { objReader.Close(); } } objReader = obj.fn_FillDataReader(ref objtblAttr, con); lst.AutoPostBack = blnAutoPostBack; lst.DataSource = objReader; lst.DataTextField = objtblAttr.strDisplayField; lst.DataValueField = objtblAttr.strValueField; lst.DataBind(); } catch (Exception ex) { if (objtblAttr.strProc != "sp_getIUDErrorDetails") { saveErrorDetails(objtblAttr.strQuery, objtblAttr.strProc, returnStringFromArr(objtblAttr.strOutputStringArr), HttpContext.Current.Request.RawUrl, "LB", ex.Message); } } finally { if (con != null) { if (con.State == ConnectionState.Open) { con.Close(); } } if (objReader != null) { if (objReader.IsClosed == false) { objReader.Close(); } } } }
public static string GetListText(System.Web.UI.WebControls.ListBox lst, string seperator) { string choice = ""; foreach (System.Web.UI.WebControls.ListItem item in lst.Items) { if (item.Selected) { if (choice.Length > 0) { choice += seperator; } choice += item.Text; } } return(choice); }
protected void DDLSector_DataBound(object sender, EventArgs e) { Label lblSector = (Label)DetailsView2.FindControl("lblSector"); System.Web.UI.WebControls.ListBox ddlSector = (System.Web.UI.WebControls.ListBox)DetailsView2.FindControl("ddlSector"); string[] arrSectors = lblSector.Text.Split(','); foreach (string szSector in arrSectors) { for (int i = 0; i < ddlSector.Items.Count; i++) { if (ddlSector.Items[i].Text == szSector.Trim()) { ddlSector.Items[i].Selected = true; } } } }
protected void lstHotel_OnSelectedIndexChanged(object sender, EventArgs e) { System.Web.UI.WebControls.ListBox obj = (System.Web.UI.WebControls.ListBox)sender; ClearHotelObject(0); if (obj.SelectedItem.Text.Substring(0, 4) == "PA -") { GetCrewAssistPAHotelInformation(GlobalCode.Field2Long(obj.SelectedValue)); } else if (obj.SelectedItem.Text.Substring(0, 4) == "HT -") { GetCrewAssistHotelInformation(obj); } else { //ClearHotelObject(0); } }
/// <summary> /// Binds the list. /// </summary> /// <param name="theListBox">The ListBox.</param> /// <param name="theDT">The dt.</param> /// <param name="theTextField">The text field.</param> /// <param name="theValueField">The value field.</param> /// <param name="SortColumnName">Name of the sort column.</param> public void BindList(System.Web.UI.WebControls.ListBox theListBox, DataTable theDT, string theTextField, string theValueField, string SortColumnName = "") { try { theDT.DefaultView.Sort = theTextField + " Asc "; if (SortColumnName != "") { theDT.DefaultView.Sort = SortColumnName + "Asc, " + theTextField + " Asc "; } theListBox.DataSource = theDT; theListBox.DataTextField = theTextField; theListBox.DataValueField = theValueField; theListBox.DataBind(); } catch { } }
public static bool SelectListIndex(System.Web.UI.WebControls.ListBox lst, string[] indexList) { for (int i = 0; i < lst.Items.Count; i++) { lst.Items[i].Selected = false; } foreach (string s in indexList) { if (s.Length > 0) { System.Web.UI.WebControls.ListItem item = lst.Items[Convert.ToInt32(s)]; item.Selected = true; } } return(true); }
//ListBox public void ListBox_Bind(System.Web.UI.WebControls.ListBox lb, DataSet ds, int value, int text) { lb.Items.Clear();//清空他的值 if (ds == null) { return; } if (ds.Tables.Count == 0) { return; } for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { ListItem litem = new ListItem(); litem.Text = ds.Tables[0].Rows[i][text].ToString().Trim(); litem.Value = ds.Tables[0].Rows[i][value].ToString().Trim(); lb.Items.Add(litem); } }
/// <summary> /// 获取多选列表的值 用,号隔开 /// </summary> /// <param name="cblControls"></param> /// <returns></returns> public static string GetListBoxSelectValue(System.Web.UI.WebControls.ListBox cblControls, string strParam) { StringBuilder sb = new StringBuilder(16); ListItem litem = null; for (int i = 0; i < cblControls.Items.Count; i++) { litem = cblControls.Items[i]; if (litem.Selected) { if (sb.Length > 0) { sb.Append(strParam); } sb.Append(litem.Value); } } return(sb.ToString()); }
public void SetListBoxItems(System.Web.UI.WebControls.ListBox lst, string Param) { try { foreach (ListItem li in lst.Items) { li.Selected = false; } foreach (string s in Param.Split(',')) { if (lst.Items.FindByValue(s) != null) { lst.Items.FindByValue(s).Selected = true; } } } catch {} }
public static string GetListValues(System.Web.UI.WebControls.ListBox lst) { string choice = ""; foreach (System.Web.UI.WebControls.ListItem item in lst.Items) { if (item.Selected) { if (choice.Length > 0) { choice += "," + item.Value; } else { choice += item.Value; } } } return(choice); }
private void RecorrerYLimpiarControles(Control MyControl) { foreach (System.Web.UI.Control MyWebServerControl in MyControl.Controls) { if (MyWebServerControl.HasControls() == false) { switch (MyWebServerControl.GetType().Name.ToString()) { case "TextBox": System.Web.UI.WebControls.TextBox MyWebControlTextBox = (System.Web.UI.WebControls.TextBox)MyWebServerControl; MyWebControlTextBox.Text = ""; break; case "CheckBox": System.Web.UI.WebControls.CheckBox MyWebControlCheckbox = (System.Web.UI.WebControls.CheckBox)MyWebServerControl; MyWebControlCheckbox.Checked = false; break; case "ListBox": System.Web.UI.WebControls.ListBox MyWebControlListBox = (System.Web.UI.WebControls.ListBox)MyWebServerControl; MyWebControlListBox.SelectedIndex = -1; break; case "DropDownList": System.Web.UI.WebControls.DropDownList MyWebControlDropDownList = (System.Web.UI.WebControls.DropDownList)MyWebServerControl; MyWebControlDropDownList.SelectedIndex = -1; break; } } else { // en el control collection vienen Panels y web controls que // a su vez, contienen controls. RecorrerYLimpiarControles(MyWebServerControl); } } }
/// <summary> /// Adds a ticket for only 1 match to the the database when all fields have been filled in correctly /// or else a error message is shown. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAddSingle_Click(object sender, EventArgs e) { System.Web.UI.WebControls.ListBox MatchChoice = (System.Web.UI.WebControls.ListBox)ucMatchesOnDateSingle.FindControl("lbMatches"); DatePicker dpDate = (DatePicker)ucMatchesOnDateDetails.FindControl("dpMatchPick"); if (dpDate.SelectedDateString == "") { dpDate = (DatePicker)ucMatchesOnDateSingle.FindControl("dpMatchPick"); } List <Match> Matches = db.GetMatches(dpDate.SelectedDate); TextBox tbAmount = (TextBox)ucTicketsAddSingle.FindControl("tbTickets"); TextBox tbPrice = (TextBox)ucTicketsAddSingle.FindControl("tbPriceTicket"); int Price = 0; int Amount = 0; if (int.TryParse(tbAmount.Text, out Amount) && int.TryParse(tbPrice.Text, out Price)) { if (Amount <= 10) { foreach (Match m in Matches) { if (m.ToString() == MatchChoice.SelectedItem.ToString()) { Match ChosenMatch = m; for (int i = 1; i <= Amount; i++) { db.AddSingle(Price, ChosenMatch); } lblError.Visible = false; } } } else { lblError.Visible = true; } } }
/// <summary> /// Confirm your purchase of a tickets of a selected match /// when name and banknumber have been filled in. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnBuy_Click(object sender, EventArgs e) { System.Web.UI.WebControls.ListBox MatchChoice = (System.Web.UI.WebControls.ListBox)TicketMatchOnDate.FindControl("lbMatches"); DatePicker dpDate = (DatePicker)TicketMatchOnDate.FindControl("dpMatchPick"); List <Match> Matches = db.GetMatches(dpDate.SelectedDate); string Name = tbName.Text; string BankNumber = tbBank.Text; foreach (Match m in Matches) { if (m.ToString() == MatchChoice.SelectedItem.ToString()) { if (db.BuyTicket(m.MatchID, Name, BankNumber)) { break; } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Tickets sold out for this match');", true); } } } }
private void Page_Load(object sender, System.EventArgs e) { HtmlForm frm = (HtmlForm)FindControl("Form1"); GHTTestBegin(frm); foreach (Type currentType in TestedTypes) { ListControl_ClearSelection(currentType); } // Clearing multiple selected items: // This cannot be tested in ListControl, because only ListBox can have multiple selection. GHTSubTestBegin("Clear multiple selection"); System.Web.UI.WebControls.ListBox lb = new System.Web.UI.WebControls.ListBox(); GHTActiveSubTest.Controls.Add(lb); try { lb.Items.Add("A"); lb.Items.Add("B"); lb.Items.Add("C"); lb.Items.Add("D"); lb.SelectionMode = ListSelectionMode.Multiple; lb.Items[0].Selected = true; lb.Items[1].Selected = true; lb.Items[2].Selected = true; lb.ClearSelection(); } catch (Exception ex) { GHTSubTestUnexpectedExceptionCaught(ex); } GHTSubTestEnd(); GHTTestEnd(); }
public void ReadStateFromFile(Page AspNetPage, ControlCollection MyControlCollection) { // intentamos leer el archivo que corresponde a la p�gina y usuario para rescatar el state if (((_UserName == "") || (_PageName == ""))) { return; } string fileName = string.Concat(_PageName, "-", _UserName); string filePath = HttpContext.Current.Server.MapPath(("~/keepstatefiles/" + fileName)); string contents = ""; try { contents = File.ReadAllText(filePath); } catch (Exception ex) { } if ((contents == "")) { return; } string[] splitout = contents.Split('¦'); foreach (string Split in splitout) { int nPosSignoIgual = Split.IndexOf("="); if ((nPosSignoIgual > 0)) { string sNombreControl = Split.Substring(0, nPosSignoIgual); string sContenido = Split.Substring((Split.Length + 1 - (Split.Length - nPosSignoIgual))); System.Web.UI.Control MyWebServerControl = FindControlRecursive(AspNetPage, sNombreControl); if ((MyWebServerControl == null)) { // TODO: Continue For... Warning!!! not translated continue; } switch (MyWebServerControl.GetType().Name.ToString()) { case "TextBox": System.Web.UI.WebControls.TextBox MyWebControlTextBox = (System.Web.UI.WebControls.TextBox)MyWebServerControl; // este caso es f�cil pues el text box solo contiene un valor (ListBox puede tener // mucho items seleccionados) MyWebControlTextBox.Text = sContenido; break; case "CheckBox": System.Web.UI.WebControls.CheckBox MyWebControlCheckbox = (System.Web.UI.WebControls.CheckBox)MyWebServerControl; if ((sContenido == "1")) { MyWebControlCheckbox.Checked = true; } else { MyWebControlCheckbox.Checked = false; } break; case "RadioButton": System.Web.UI.WebControls.RadioButton MyWebControlRadioButton = (System.Web.UI.WebControls.RadioButton)MyWebServerControl; if ((sContenido == "1")) { MyWebControlRadioButton.Checked = true; } else { MyWebControlRadioButton.Checked = false; } break; case "ListBox": { System.Web.UI.WebControls.ListBox MyWebControlListBox = (System.Web.UI.WebControls.ListBox)MyWebServerControl; string[] sArrayOfStrings = sContenido.Split(';'); foreach (string MyString in sArrayOfStrings) { foreach (ListItem MyListItem in MyWebControlListBox.Items) { if ((MyListItem.Text == MyString)) { MyListItem.Selected = true; } } } break; } case "CheckBoxList": { System.Web.UI.WebControls.CheckBoxList MyWebControlCheckBoxList = (System.Web.UI.WebControls.CheckBoxList)MyWebServerControl; string[] sArrayOfStrings = sContenido.Split(';'); foreach (string MyString in sArrayOfStrings) { foreach (ListItem MyListItem in MyWebControlCheckBoxList.Items) { if ((MyListItem.Text == MyString)) { MyListItem.Selected = true; } } } break; } case "DropDownList": System.Web.UI.WebControls.DropDownList MyWebControlDropDownList = (System.Web.UI.WebControls.DropDownList)MyWebServerControl; MyWebControlDropDownList.SelectedValue = sContenido; break; } } } }
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); } } }
/// <summary> /// 设置 下拉列表的值 用,号隔开 /// </summary> /// <param name="cblControls"></param> /// <param name="strValue"></param> public static void SetGetListBoxSelectValue(System.Web.UI.WebControls.ListBox cblControls, string strValue) { SetGetListBoxSelectValue(cblControls, strValue, ","); }
/// <summary> /// 获取多选列表的值 用,号隔开 /// </summary> /// <param name="cblControls"></param> /// <returns></returns> public static string GetListBoxSelectValue(System.Web.UI.WebControls.ListBox cblControls) { return(GetListBoxSelectValue(cblControls, ",")); }