Asp. NET custom Web server control-dropdownlist/select drop-down list control

Source: Internet
Author: User

Using system;using system.collections.generic;using system.componentmodel;using system.linq;using System.Text;using System.web;using system.web.ui;using system.web.ui.webcontrols;//Custom Web server Control-drop-down list namespace mycontrols{[ Defaultproperty ("Text")] [ToolBoxData ("<{0}:myselect runat=server></{0}:myselect>")] [ParseChildren (        True, "Items")]//Stipulate public class Myselect:webcontrol {[Bindable (True)] [Category ("appearance")]        [DefaultValue ("")] [Localizable (true)] public string Text {get {string s = (string) views                tate["Text"]; Return ((s = = null)?            STRING.EMPTY:S);            } set {viewstate["Text"] = value; }} [DesignerSerializationVisibility (designerserializationvisibility.content)]//print the label as content public Li                St<selectitem> items{get{if (viewstate["Items"]==null) {viewstate["Items"] = new list<selectitem> ();           } return (list<selectitem>) viewstate["Items";            } set{viewstate["Items"] = value; }} [DesignerSerializationVisibility (designerserializationvisibility.content)]//print the label public in the form of content Siz                    E Size {get {if (viewstate["Size"] = = null) {                viewstate["size"] = new Size ();            } return (size) viewstate["size"];            } set {viewstate["Size"] = value; }} public override void RenderBeginTag (HtmlTextWriter writer) {this. Style.add ("Width", Size.width + "px"); Add style, Width this. Style.add ("Height", Size.Height + "px"); Add style, height base.        RenderBeginTag (writer);          } protected override HtmlTextWriterTag Tagkey {get  {return htmltextwritertag.select;//drop-down list label}}  protected override void RenderContents (HtmlTextWriter output) {//Print drop-down list contents foreach (SelectItem Item in Items) {output. Write ("<option value= '" +item. Value+ "' >" +item.            text+ "</option>"); }        }    }}

  

Using system;using system.collections.generic;using system.linq;using system.text;//<!-- Custom Server drop-down list control sub-label namespace mycontrols{public    class SelectItem    {public        string value {set; get;}//Selected value Public        string Text {set; get;}//Selected text content public        SelectItem () {} public        SelectItem (string text, String Valu E) {This            . Text = text;            This. value = value;}}}    

  

Using system;using system.collections.generic;using system.linq;using system.text; <cc1:mybutton id= "MyButton1" size-height= "the" "size-width=" 290  usage, used for this internal attribute//defines a size class, It contains the width of the namespace mycontrols{public   class Size    {public       int width {set; get;}       public int Height {set; get;}       Public Size (Int. width,int height) {this           . width = width;           This. Height = height;       }       Public Size (): This (100,100) {}}    }

  

<%@ page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%><%@ Register Assembly= "MyControls" namespace= "MyControls" tagprefix= "CC1"%><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

  

ASP. NET custom Web server control-dropdownlist/select drop-down list control

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.