public MyComboBox() { _dropDown = new MyDropDown() { Width = 200, Height = 200 }; }
protected void Page_PreRender(object sender, EventArgs e) { // insert into the drop down the user listItem MyDropDown.Items.Clear(); foreach (ListItem listItem in ListItems) { MyDropDown.Items.Add(listItem); } if (!hasDataSource) { if (tableName != "") { using (MySqlConnection conn = new MySqlConnection(ConnStr)) { string sql = String.Format("Select {0},{1} From {2} {3} ", this.DataTextField, DataValueField, this.tableName, this.dataOrderField == "" ? "" : "Order By " + this.dataOrderField); MySqlDataAdapter da = new MySqlDataAdapter(sql, conn); DataSet ds = new DataSet(); da.Fill(ds, "dropDown"); MyDropDown.DataSource = ds.Tables["dropDown"].DefaultView; MyDropDown.DataBind(); } } } else { MyDropDown.DataBind(); } TextBoxHolderDiv.Attributes["class"] = this.cssClass; string mySelected = DataFieldValue; string a = SelectedValue; if (!String.IsNullOrEmpty(mySelected) && MyDropDown.Items.FindByValue(mySelected) != null) { MyDropDown.SelectedItem.Selected = false; for (int i = 0; i < MyDropDown.Items.Count; i++) { MyDropDown.Items[i].Selected = false; if (MyDropDown.Items[i].Value == mySelected) { MyDropDown.Items[i].Selected = true; myspan.InnerText = MyDropDown.Items[i].Text; MyHiddenField.Value = MyDropDown.Items[i].Text; MyHiddenFieldVlaue.Value = MyDropDown.Items[i].Value; } } } else { for (int i = 0; i < MyDropDown.Items.Count; i++) { if (MyDropDown.Items[i].Selected) { myspan.InnerText = MyDropDown.Items[i].Text; MyHiddenField.Value = MyDropDown.Items[i].Text; MyHiddenFieldVlaue.Value = MyDropDown.Items[i].Value; } } } MyDropDown.Attributes.Add("onchange", "javascript:document.getElementById('" + myspan.ClientID + "').innerHTML=this.options[this.selectedIndex].text;document.getElementById('" + MyHiddenField.ClientID + "').value=this.options[this.selectedIndex].text;document.getElementById('" + MyHiddenFieldVlaue.ClientID + "').value=this.options[this.selectedIndex].value;" + onClientSelectedChanged); }
private void InitPrint() { //加载打印名称 if (ddlPrintName == null) { ddlPrintName = new MyDropDown(pal_Print_Box, new Point(151, 27), "setPrint_Name", toolTip1); string Prints = string.Empty; foreach (string pName in PrinterSettings.InstalledPrinters) { Prints += pName + ";"; } ddlPrintName.Items = Prints.TrimEnd(';').Split(';'); ddlPrintName.Draw(); } string tmp_PrintName = iniClass.IniReadValue("Print", "Name"); ddlPrintName.SelectItem = tmp_PrintName; //加载打印联数 if (ddlPrintJoint == null) { string tmp_PrintJointEnum = iniClass.IniReadValue("Print", "JointEnum"); ddlPrintJoint = new MyDropDown(pal_Print_Box, new Point(151, 83), "setPrint_Joint", toolTip1); ddlPrintJoint.Items = tmp_PrintJointEnum.Split(';'); ddlPrintJoint.Draw(); } string tmp_PrintJoint = iniClass.IniReadValue("Print", "JointValue"); ddlPrintJoint.SelectItem = tmp_PrintJoint; //加载是否开启打印 bool tmp_IsOpenPrint = bool.Parse(iniClass.IniReadValue("Print", "OpenPrint")); if (tmp_IsOpenPrint) { ptb_Print_IsOpen.Image = System.Drawing.Image.FromFile("Image/sys_icon_on.png"); } else { ptb_Print_IsOpen.Image = System.Drawing.Image.FromFile("Image/sys_icon_off.png"); } ptb_Print_IsOpen.Tag = tmp_IsOpenPrint; }
public void DataBind() { MyDropDown.DataBind(); }