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. phpcms pc标签 start不生效的原因

    start 和 page 参数不可同时使用,使用了page参数 会造成start 参数无效

  2. windows安装go-sqlite3失败,提示找不到gcc

    windows安装go-sqlite3失败,提示找不到gcc go get github.com/mattn/go-sqlite3时失败,提示exec: “gcc”: executable file ...

  3. easyui refresh 刷新两次的解决方法(推荐)

    //这样写刷新两次 $("#windowid").window('refresh','url01.php'); $("#windowid").window('o ...

  4. MySQL监控和预警

    https://blog.csdn.net/zhaowenbo168/article/details/53219860 1.摘要 本人从事Java Web开发,在项目开发中会用到很多中间件,本文主要介 ...

  5. C#.NET常见问题(FAQ)-如何将cs文件编译成dll文件 exe文件 如何调用dll文件

    比如我要把TestDLL.cs文件编译成dll文件,则在命令提示符下,输入下面的命令,生成的文件为TestDLL.dll csc /target:library TestDLL.cs 注意前提是你安装 ...

  6. 单页WEB应用(三),Chat聊天模块

    Chat 聊天模块 这个模块应该就是该书全篇的唯一一个模块吧,后面差点儿全部的篇章都环绕这个模块去实现的,只是就通过这一个模块的实现和上线,也能体现单页应用开发到公布上线的整个过程,毕竟后面的数据.通 ...

  7. ListView与Button共存问题

        转载:http://blog.csdn.net/xinqiqi123/article/details/6458030 ListView 和 其它能触发点击事件的widget无法一起正常工作的原 ...

  8. WebService 之 身份验证

    在项目开发,我们经常会使用WebService,但在使用WebService时我们经常会考虑到了WebService是安全问题,很容易想到通过一组用户名与密码来防止非法用户的调用 . 一.Networ ...

  9. TCP相关面试题总结

    1.TCP三次握手过程 wireshark抓包为:(wireshark会将seq序号和ACK自己主动显示为相对值) 1)主机A发送标志syn=1,随机产生seq =1234567的数据包到server ...

  10. MISRA-C++ 2008