. NET composite control can be input drop-down controls

Source: Internet
Author: User
Use the system;
Use System.Collections.Generic;
Use System.ComponentModel;
Use System.Text;
The use of system.web;
Use the System.Web.UI program;
Use System.Web.UI.WebControls;
Used in System.Collections;

Namespace Qc_control
{
< summary >
Custom Input drop-down box class
</Summary >
[ToolBoxData ("<{0}:custominputdropdowncontrol RUNAT = server > </{0}:custominputdropdowncontrol>")]
public class Custominputdropdowncontrol: text box
{

Ddllistitem of private DropDownList = new DropDownList (); drop-down box
Private text Box Txtbox = new TextBox ();
_values of private hashtable = new Hashtable (); Value used to bind the drop box

< summary >
Key value reference variable set/Get encapsulation method
</Summary >
Public Hashtable projects
{
Get
if (ViewState ["value"] = = NULL)
{

ViewState ["value"] = new Hashtable ();

}
Other {}

Hashtable s = (hash table) of ViewState ["value"];
return s;
}
set {ViewState ["value"] = value;}
}


< summary >
Default constructor
Initialized DropDownList and Hashtable instance variables
</Summary >
Public Custominputdropdowncontrol ()
{
This._values = new Hashtable ();
This.ddllistitem = new DropDownList ();
}

< summary >
Overriding the control class rendering method body
</Summary >
<param name = "Output" > </param>
Protection overwrite invalid render (output of HtmlTextWriter)
{Ddllistitem. ID = "DDL" + base.id;
Txtbox.id = "txt"+ base.id;
The beginning of the framework
Output. Write ("< table cellspacing = ' 0 ' cellpadding =" 0 "boundary = ' 0 ' > <TR> <td ALIGN =" Left "> the position of <span style = ' is: absolute; FRAME: for 1pt solid #c1c1c1; overflow: hidden; width:188px, Height: 19px; Clip: Rectangle ( -1px 190px 190px 170 pixels); > ");

ClientID is used here because when in the card option. NET program will automatically name the Base.id
DDLLISTITEM.ATTRIBUTES.ADD ("onchange", Getfocusvalue (txtbox.id,ddllistitem.id));
DDLLISTITEM.ATTRIBUTES.ADD ("Style", "width: 190px; Family: The margin-top:-2px of the song body; );
TXTBOX.ATTRIBUTES.ADD ("Style", "width: 170 megapixels, Height: 15px; frame: 0pt;" );
Traverse the data into the drop-down box object
, if (this. Item.count> 0)
{
The foreach (String Item.keys key)
{
List item item = new ListItem ();
Item. Value = key;
Item. Text = ToString () of project [key];
DDLLISTITEM.ITEMS.ADD (project);
}
}
Ddllistitem.rendercontrol (output);
Output. Write ("</span> 's <span style = ' position is: absolute; border top: solid for 1pt#c1c1c1; left box: 1pt solid #c1c1c1; border bottom: solid for 1pt#c1c1c1; width: 170 Megapixels, Height: 19px; " > ");
Txtbox.rendercontrol (output);
End of frame
Output. Write ("</span> </td> </t> </table>");
}

Responding to Event methods
Common string Getfocusvalue (string txtID, Strings Ddlid)
{
Return to "Java class" + "Cript:" + "document.getElementById ('" + txtID + "). The value = document.getElementById (' + Ddlid + ') is available for options [ document.getElementById (' "+ Ddlid +" '). SelectedIndex]. Value; " The ToString ();

}
}
}
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.