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;
//自定义web服务器控件-下拉列表
namespace MyControls
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:MySelect runat=server></{0}:MySelect>")]
[ParseChildren(true,"Items")] //规定
public class MySelect : WebControl
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
} set
{
ViewState["Text"] = value;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] //以内容的形式打印标签
public List<SelectItem> Items{
get{
if(ViewState["Items"]==null){
ViewState["Items"] = new List<SelectItem>();
}
return (List<SelectItem>)ViewState["Items"];
}
set{
ViewState["Items"] = value;
}
} [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]//以内容的形式打印标签
public Size 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"); //增加样式,宽度
this.Style.Add("Height", Size.Height + "px"); //增加样式,高度
base.RenderBeginTag(writer);
}
protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Select;//下拉列表标签
}
}
protected override void RenderContents(HtmlTextWriter output)
{
//打印下拉列表内容
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; //<!--自定义服务器下拉列表控件的子标签
namespace MyControls
{
public class SelectItem
{
public string Value { set; get; } //选择的值
public string Text { set; get; } //选择的文本内容
public SelectItem() { }
public SelectItem(string text, string value) {
this.Text = text;
this.Value = value;
}
}
}

  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; //<cc1:MyButton ID="MyButton1" Size-Height="30" Size-Width="290" />用法,用于这种内部属性
//定义一个大小的类,里面包含了宽高
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">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<!--自定义服务器下拉列表控件-->
<cc1:MySelect Size-Height="100" Size-Width="100" ID="MySelect1" runat="server">
<cc1:SelectItem Value="1" Text="选择一" />
<cc1:SelectItem Value="2" Text="选择二" />
<cc1:SelectItem Value="3" Text="选择三" />
</cc1:MySelect>
</div>
</form> </body>
</html>

  

ASP.NET自定义Web服务器控件-DropDownList/Select下拉列表控件的更多相关文章

  1. 专用于ASP.Net Web应用程序的日期控件

     原文引入:http://blog.csdn.net/nileel/article/details/1566051 专用于ASP.Net Web应用程序的日期控件 分类: ASP.NET/C#2007 ...

  2. 基于Jquery的下拉列表控件(个人觉得实用)

    Selectize.js Selectize 是一个基于 jQuery 的 <select> UI 控件,对于标签选择和下拉列表功能非常有用. Selectize 的目标是通过简单而强大的 ...

  3. 【番外篇】ASP.NET MVC快速入门之免费jQuery控件库(MVC5+EF6)

    目录 [第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) [第二篇]ASP.NET MVC快速入门之数据注解(MVC5+EF6) [第三篇]ASP.NET MVC快速入门之安全策 ...

  4. 2017年12月17日 ASP.NET 12个表单元素&&简单控件/复合控件

    12个表单元素可以分为三大类 第一类:文本类 <input type = "text" /> //普通文本框 <input type = "passwo ...

  5. FineUI第八天----下拉列表控件

    下拉列表控件 3.模拟树的下拉列表: 其他的控件都跟Asp.net的差不多.

  6. ASP.NET MVC中加载WebForms用户控件(.ascx)

    原文:ASP.NET MVC中加载WebForms用户控件(.ascx) 问题背景 博客园博客中的日历用的是ASP.NET WebForms的日历控件(System.Web.UI.WebControl ...

  7. 安卓开发16:Spinner 下拉列表控件

    Spinner 下拉列表控件 创建一个activity_main.xml文件: <RelativeLayout xmlns:android="http://schemas.androi ...

  8. Android 自定义View 三板斧之一——继承现有控件

    通常情况下,Android实现自定义控件无非三种方式. Ⅰ.继承现有控件,对其控件的功能进行拓展. Ⅱ.将现有控件进行组合,实现功能更加强大控件. Ⅲ.重写View实现全新的控件 本文重点讨论继承现有 ...

  9. Atitit. .net c# web 跟clientwinform 的ui控件结构比較

    Atitit. .net c# web 跟clientwinform 的ui控件结构比較 .net   4.5 webform Winform 命名空间 System.Web.UI.WebContro ...

随机推荐

  1. Linux经常使用命令(三) - pwd

    Linux中用 pwd 命令来查看"当前工作文件夹"的完整路径. 简单得说,每当你在终端进行操作时.你都会有一个当前工作文件夹. 在不太确定当前位置时.就会使用pwd来判定当前文件 ...

  2. Typescript declaration: Merge a class and an interface

    参考: https://stackoverflow.com/questions/47670959/typescript-declaration-merge-a-class-and-an-interfa ...

  3. Wndows 主进程(Rundll32)已停止工作

        打开电脑,出现"windows 主进程(Rundll32)已停止工作",百度了一下,是文件损坏了.     下载一个新的文件,替换即可,若遇到权限问题,使用魔方工具中的设置 ...

  4. IIS 之 连接数、并发连接数、最大并发工作线程数、队列长度、最大工作进程数

    一.IIS连接数 一般购买过虚拟主机的朋友都熟悉购买时,会限制IIS连接数,顾名思义即为IIS服务器可以同时容纳客户请求的最高连接数,准确的说应该叫“IIS限制连接数”. 客户请求的连接内容包括: [ ...

  5. POSIX 线程 – pthread_sigmask

    http://www.cnblogs.com/qq78292959/archive/2012/04/05/2432985.html 概念 按照 POSIX, 异步 (外部) 信号发送到整个进程. 所有 ...

  6. Java实现根据输入的日期以及天数,获取此日期之后的天数的工作日

    public static void main(String[] args) { List<String> list = new ArrayList<String>();//节 ...

  7. poj 1879 Truck History

    本题链接:点击打开链接 题目大意: 输入n表示卡车辆数,输入每辆卡车编号.即长度为7的字符串,每辆卡车编号均可由其他类型编号衍生过来,求由当中一辆衍生出其他全部的最小衍生次数(有一个字符不同就需衍生一 ...

  8. webpack entry和output配置属性

    1.entry entry的三种配置方式: (1)传递字符串: 单个入口语法:传递一个字符串 entry: './src/js/main.js', (2)传递数组 将创建“多个主入口(multi-ma ...

  9. ITOO之底层关系

    一.pom.xml文件关系图: 以基础系统中学生这条线为例: 图一:pom.xml文件关系图 图说明: 该项目是Maven项目,使用pom.xml文件对项目进行管理 管理类:(非阴影部分) Itoo- ...

  10. eclipse to avoid the message, disable the...

      标题 CreateTime--2018年5月9日10:38:15 Author:Marydon 1.问题描述 2.问题解析 这是因为eclipse的智能提示超时引起的,将超时间调大即可,如:200 ...