[DefaultProperty("Text"),
ToolboxData("<{0}:myC_DataDropList runat=server></{0}:myC_DataDropList>")]
public class myC_DataDropList : WebControl,
INamingContainer , IPostBackDataHandler
{
private object objDs ;
private System.Web.UI.WebControls.ListBox list = new ListBox() ;
private TextBox txtText =new TextBox() ;
//private TextBox txtValue ;// public string Text
// {
// get
// {
// return txtText.Text;
// }
//
// set
// {
// txtText.Text = value;
// }
// }
public string Value
{
get
{
EnsureChildControls( );
return list.SelectedValue;
return ViewState["value"].ToString() ;
}
}
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public object DataSource
{
set
{
object tem = new object() ;
tem = value;
if((tem != null) && ( tem is System.Collections.IList || tem is System.Collections.IEnumerator ))
objDs = value;
}
get
{
return objDs;
}
}
/// <summary>
/// 将此控件呈现给指定的输出参数。
/// </summary>
/// <param name="output"> 要写出到的 HTML 编写器 </param>
protected override void Render(HtmlTextWriter output)
{
//output.Write(Text);
txtText.RenderControl(output);
output.Write("<Div id="+ "div" + this.UniqueID +" style=\"display:none\">" );
list.RenderControl(output);
output.Write("</div>") ;
output.AddAttribute("onmouseout","hideDiv(" + "div" + this.UniqueID + ");");
output.AddAttribute("onmouseover","showDiv(" + txtText.ClientID + "," + "div" + this.UniqueID + ");");
} public override void DataBind()
{
//EnsureChildControls( ); base.DataBind ();
this.Controls.Clear();
list.DataSource= objDs;
list.DataBind();
}
protected override void CreateChildControls()
{
base.CreateChildControls ();
this.Controls.Clear();
//this.txtText = new TextBox() ;
txtText.ID= "txt" ;
this.Controls.Add(txtText); txtText.Attributes.Add("onclick","showDiv(" + txtText.ClientID + "," + "div" + this.UniqueID + ");");
// Panel pn = new Panel ();
// pn.ID = "div" ;
// pn.Controls.Add (list) ;
list.ID="lst" ;
Controls.Add(list);
list.Attributes.Add("onclick","setValue(" + list.ClientID + "," + txtText.ClientID + "," + "div" + this.UniqueID
+ ")");
//this.Attributes.Add("onmouseout","hideDiv(" + "div" + this.UniqueID + ");");
//this.Attributes.Add("onmouseover","showDiv(" + txtText.ClientID + "," + "div" + this.UniqueID + ");");
//this.Controls.Add(pn);
} protected override void LoadViewState(object savedState)
{
base.LoadViewState (savedState);
} protected override object SaveViewState()
{
return base.SaveViewState ();
} bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
{ string value = postCollection["list"];// if (value != null)
// {
// bool newValue = (String.Compare(value, "true", true) == 0);
// bool oldValue = Selected;
//
// Selected = newValue;
//
// // If there is a change, raise a change event.
// return (newValue != oldValue);
// } return false;
} void IPostBackDataHandler.RaisePostDataChangedEvent()
{
// There was a change, so raise any events.
// if (SelectedChanged != null)
// {
// SelectedChanged(this, EventArgs.Empty);
// }
} }
ToolboxData("<{0}:myC_DataDropList runat=server></{0}:myC_DataDropList>")]
public class myC_DataDropList : WebControl,
INamingContainer , IPostBackDataHandler
{
private object objDs ;
private System.Web.UI.WebControls.ListBox list = new ListBox() ;
private TextBox txtText =new TextBox() ;
//private TextBox txtValue ;// public string Text
// {
// get
// {
// return txtText.Text;
// }
//
// set
// {
// txtText.Text = value;
// }
// }
public string Value
{
get
{
EnsureChildControls( );
return list.SelectedValue;
return ViewState["value"].ToString() ;
}
}
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public object DataSource
{
set
{
object tem = new object() ;
tem = value;
if((tem != null) && ( tem is System.Collections.IList || tem is System.Collections.IEnumerator ))
objDs = value;
}
get
{
return objDs;
}
}
/// <summary>
/// 将此控件呈现给指定的输出参数。
/// </summary>
/// <param name="output"> 要写出到的 HTML 编写器 </param>
protected override void Render(HtmlTextWriter output)
{
//output.Write(Text);
txtText.RenderControl(output);
output.Write("<Div id="+ "div" + this.UniqueID +" style=\"display:none\">" );
list.RenderControl(output);
output.Write("</div>") ;
output.AddAttribute("onmouseout","hideDiv(" + "div" + this.UniqueID + ");");
output.AddAttribute("onmouseover","showDiv(" + txtText.ClientID + "," + "div" + this.UniqueID + ");");
} public override void DataBind()
{
//EnsureChildControls( ); base.DataBind ();
this.Controls.Clear();
list.DataSource= objDs;
list.DataBind();
}
protected override void CreateChildControls()
{
base.CreateChildControls ();
this.Controls.Clear();
//this.txtText = new TextBox() ;
txtText.ID= "txt" ;
this.Controls.Add(txtText); txtText.Attributes.Add("onclick","showDiv(" + txtText.ClientID + "," + "div" + this.UniqueID + ");");
// Panel pn = new Panel ();
// pn.ID = "div" ;
// pn.Controls.Add (list) ;
list.ID="lst" ;
Controls.Add(list);
list.Attributes.Add("onclick","setValue(" + list.ClientID + "," + txtText.ClientID + "," + "div" + this.UniqueID
+ ")");
//this.Attributes.Add("onmouseout","hideDiv(" + "div" + this.UniqueID + ");");
//this.Attributes.Add("onmouseover","showDiv(" + txtText.ClientID + "," + "div" + this.UniqueID + ");");
//this.Controls.Add(pn);
} protected override void LoadViewState(object savedState)
{
base.LoadViewState (savedState);
} protected override object SaveViewState()
{
return base.SaveViewState ();
} bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
{ string value = postCollection["list"];// if (value != null)
// {
// bool newValue = (String.Compare(value, "true", true) == 0);
// bool oldValue = Selected;
//
// Selected = newValue;
//
// // If there is a change, raise a change event.
// return (newValue != oldValue);
// } return false;
} void IPostBackDataHandler.RaisePostDataChangedEvent()
{
// There was a change, so raise any events.
// if (SelectedChanged != null)
// {
// SelectedChanged(this, EventArgs.Empty);
// }
} }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货