Secondary DROPDOWNLIST control source code
Put the source code here, but it is not very satisfactory.
There is a small problem, it is to get the value of small class, because a function is added to the control, if the control will automatically select the appropriate options accordingly when you bring a small class, and drive the large class options. This is a conflict: obtain the impact of the value of the small class and the value of the initial small class.
I started to be busy again, and I wondered back and modified.
The source code is as follows:
Using
System.Text;
Using
System.globalization;
Using
System.Web;
Using
System.Web.ui;
Using
System.Web.ui.WebControls;
Using
System.Web.ui.htmlControls;
Using
System.Web.ui.design;
Using
System;
Using
System.drawing.design;
Using
System.drawing;
Using
System.data;
Using
System.collections;
Using
System.componentmodel;
Using
System.componentmodel.design;
Using
System.collections.Specialized;
Namespace
Flyangel.component.Webui
{/ ** //// /// AutoSelectDroplist's summary description. /// summary> [ToolboxData ( "<{0}: AutoSelectDropList runat = server> {0}: AutoSelectDropList>")] public class AutoSelectDropList: Control, INamingContainer, IPostBackEventHandler, IPostBackDataHandler {DropDownList _childdropdownlist = new DropDownList ( ); DropDownList _fatherdropdownlist = new DropDownList (); HtmlInputHidden _hideinput = new HtmlInputHidden (); #region property attribute data source provided the data source provided #region private DataSet _ds; [Browsable (false), Category ( "data source settings"), Description ("Set the data source for the control, according to the class library features, the type is DataSet, including two DATATABLE, the Father table placed in the Father table, and place all subcords in the Child table.
")] Public DataSet DataSource {get {return (DataSet) HttpContext.Current.Cache [" AutoSelectDropList "];} set {_ds = value; if (HttpContext.Current.Cache [" AutoSelectDropList "] == null) {HttpContext. Current.cache.insert ("AutoSelectrDroplist", _ DS);}}} #endregion belongs to the ID Name #Region belongs to FORM ID Name Private string _FormName = "form1"; ////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // / < Summary> [Browsable (True), Description ("Form Value), Category (" form ID settings), Category ("form ID settings"), Category ("form ID settings", DEFAULTVALUE ] Public string setformid {set {_formname = value;} get {return _formname;}} #endregion childid setting, used to make a child selection, and reverse control the selection of the parent bar #Region ChildID settings, used to make a sub-column Selection and reverse control the selection of the parent / ** //// /// Select /// summary> [Browsable (TRUE), Description ( "ChildID settings, used to perform the selection of childbar, and reverse the choice of the parent bar! "), Category (" ChildID Settings "), DefaultValue (" 0 ")] private string _setselectchildid =" 0 "; public string SetSelectedChildID {get {return _setselectchildid;} set {_setselectchildid = value;}} [Browsable (false), Description ("FatherID settings, the choice of parent crew, and reverse the selection of the parent]!"), Category ("FatherId Settings"), DefaultValue ("0")] private string _setselectfatherId = "0"; 0 ";
private String SetSelectedFatherID {get {return _setselectfatherid;} set {_setselectfatherid = value;}} #endregion data field Data field provided #region provided private String _fatherfieldname = "ClassName"; / ** //// /// Parent Class name /// summary> [Browsable (TRUE), Description ("Parent class name in the data table in the corresponding record name field, such as default!"), Category ("Data Field Settings"), DefaultValue "ClassName")] public String SetFatherFieldName {set {_fatherfieldname = value;} get {return _fatherfieldname;}} private String _fatherfieldid = "ClassID"; / ** //// /// parent ID /// summary> [Browsable (TRUE), Description ("Parent class name in the data table, such as default!"), category ("Data Field Settings"), DefaultValue ("ClassID")] Public string setfatherfieldId {set {_fatherfieldidiD = value;} get {return _fatherfield;}} private string _ChildfieldName = "classname"; / ** //// /// Submmary /// summary> [Browsable (TRUE), Description ("Sub-name Name in the data table, the corresponding record name field, such as the default! "), Category (" Data Field set "), DefaultValue (" name ")] public String SetChildFieldName {set {_childfieldname = value;} get {return _childfieldname;}} private String _childfieldid =" ClassID "; / ** // // /// Sub-class ID /// summary> [Browsable (TRUE), Description ("Sub-class name in the corresponding record ID field in the data table,
Such as default! "), Category (" Data Field set "), DefaultValue (" ClassID ")] public String SetChildFieldID {set {_childfieldid = value;} get {return _childfieldid;}} private String _parentid =" ParentID "; / ** // // /// Parent class ID /// summary> [Browsable (TRUE), Description ("Sub-class name in the corresponding record ID field in the data table, such as the default!"), Category "data field settings"), DefaultValue ( "ParentID")] public String SetParentID {set {_parentid = value;} get {return _parentid;}} #endregion #region public string GetFatherSelectedValue {get {return _fatherdropdownlist.SelectedValue;}} public String getChildSelectedValue {get {return _hideinput.value;}} #endregion #endregion public void renderatdesigntime () {if (! page.ispostback) {createchildControls ();}} prote cted override void CreateChildControls () {Controls.Clear (); _hideinput.ID = "SCvalue"; _hideinput.Value = "0"; Controls.Add (_hideinput); _fatherdropdownlist.ID = "fatherid"; _fatherdropdownlist.Attributes.Add ( "Onchange", "ChangeLocation". " this.clientid " _fatherid.Options [document. " _ _FormName ". " this.clientid " _fatherid.selectedIndex] .value) ") ListItem _newli = new listitem ();
_newli.Text = "a column"; _newli.Value = "0"; _fatherdropdownlist.Items.Add (_newli); if (SetSelectedChildID = "0"!) {GetFatherIDFormChildID ();} int _tempfatheridstr = 0; for (int i = 0; i <(DataSource.Tables [0] .Rows.count); i ) {listitem _newlii = new ListItem (); _newlii.value = DataSource.tables [0] .rows [i] [_ fatherfieldidId] .tostring (); _Newlii.text = datasource.tables [0] .rows [i] [_ fatherfieldname] .tostring (); _fatherdropdownlist.items.add (_newlii); if (setselectedfatherid == DataSource.tables [0] .rows [i ] [_ fatherfieldid] .ToString ()) {_tempfatheridstr = i 1;}} Controls.Add (_fatherdropdownlist); _fatherdropdownlist.SelectedIndex = _tempfatheridstr; _childdropdownlist.ID = "childid"; _childdropdownlist.Attributes.Ad D ("Onchange", "ChangeChild (Document." "." this.clientid "_ChildID.Options [Document." _FormName "." this.clientid "_child.SselectedIndex] .value) "); int _tempchildidstr = 0;! if (SetSelectedChildID =" 0 ") {DataView _temdv = new DataView (DataSource.Tables [1]); string _filterstr = _parentid " = " SetSelectedFatherID; _temdv.RowFilter = _filterstr; for (int JJ = 0; JJ <_TEMDV.COUNT;
jj ) {ListItem _newlijai = new ListItem (); _newlijai.Value = _temdv [jj] [_ childfieldid] .ToString (); _newlijai.Text = _temdv [jj] [_ childfieldname] .ToString (); _childdropdownlist.Items.Add (_newlijai ); if (SetSelectedChildID == _temdv [jj] [_ childfieldid] .ToString ()) {_tempchildidstr = jj;}}} else {ListItem _newliji = new ListItem (); _newliji.Text = "two column"; _newliji.Value = "0"; _childdropdownlist.Items.Add (_newliji);} Controls.Add (_childdropdownlist); _childdropdownlist.SelectedIndex = _tempchildidstr; AddClientScript ();} private void GetFatherIDFormChildID () {for (int j = 0; j <(DataSource .Tables [1] .rows.count); J ) { if (SetSelectedChildID == DataSource.Tables [1] .Rows [j] [_ childfieldid] .ToString ()) {SetSelectedFatherID = DataSource.Tables [1] .Rows [j] [_ parentid] .ToString ();}}} IPostBackEventHandler Implement # region ipostbackeventhandler implemementation / ** //// /// Implementing interface, enabling the control to handle events that cause the form to the server.
/// summary> /// param> public void RaisePostBackEvent (string args) {} #endregion IPostBackDataHandler Implementation # region IPostBackDataHandler Implementation / ** //// / // Implement the interface to process the backfelt data for the server control. /// summary> /// The main identifier of the control. param> /// Collection of all incoming name values. param> /// return, copypostdata (String Pkey, NameValueCollection Pcol) {Return False;} / ** //// // Implementation Interface, with signal requirements server control object to notify the ASP.NET application The status of the control has changed. /// summary> public virtual void RaisePostDataChangedEvent () {OnPageChanged (EventArgs.Empty);} #endregion PageChanged Event # region PageChanged Event public event EventHandler PageChanged; #endregion OnPageChanged Method # region OnPageChanged Method / ** //// /// triggers event. This allows you to provide custom handles for events. /// summary> /// One , which contains event data.
Param> protected virtual void OnPageChanged (EventArgs e)! {If (this.PageChanged = null!) {PageChanged (this, e);}} #endregion private void AddClientScript () {if (Page.IsClientScriptBlockRegistered ( "clientScript" )) {StringBuilder stringScript = new StringBuilder (); stringScript.Append ( "<- design: flash1313699@hotmail.com QQ:! 3337002 ->"); stringScript.Append ( "