ASP.NET自定义Web服务器控件-DropDownList/Select下拉列表控件
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下拉列表控件的更多相关文章
- 专用于ASP.Net Web应用程序的日期控件
原文引入:http://blog.csdn.net/nileel/article/details/1566051 专用于ASP.Net Web应用程序的日期控件 分类: ASP.NET/C#2007 ...
- 基于Jquery的下拉列表控件(个人觉得实用)
Selectize.js Selectize 是一个基于 jQuery 的 <select> UI 控件,对于标签选择和下拉列表功能非常有用. Selectize 的目标是通过简单而强大的 ...
- 【番外篇】ASP.NET MVC快速入门之免费jQuery控件库(MVC5+EF6)
目录 [第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) [第二篇]ASP.NET MVC快速入门之数据注解(MVC5+EF6) [第三篇]ASP.NET MVC快速入门之安全策 ...
- 2017年12月17日 ASP.NET 12个表单元素&&简单控件/复合控件
12个表单元素可以分为三大类 第一类:文本类 <input type = "text" /> //普通文本框 <input type = "passwo ...
- FineUI第八天----下拉列表控件
下拉列表控件 3.模拟树的下拉列表: 其他的控件都跟Asp.net的差不多.
- ASP.NET MVC中加载WebForms用户控件(.ascx)
原文:ASP.NET MVC中加载WebForms用户控件(.ascx) 问题背景 博客园博客中的日历用的是ASP.NET WebForms的日历控件(System.Web.UI.WebControl ...
- 安卓开发16:Spinner 下拉列表控件
Spinner 下拉列表控件 创建一个activity_main.xml文件: <RelativeLayout xmlns:android="http://schemas.androi ...
- Android 自定义View 三板斧之一——继承现有控件
通常情况下,Android实现自定义控件无非三种方式. Ⅰ.继承现有控件,对其控件的功能进行拓展. Ⅱ.将现有控件进行组合,实现功能更加强大控件. Ⅲ.重写View实现全新的控件 本文重点讨论继承现有 ...
- Atitit. .net c# web 跟clientwinform 的ui控件结构比較
Atitit. .net c# web 跟clientwinform 的ui控件结构比較 .net 4.5 webform Winform 命名空间 System.Web.UI.WebContro ...
随机推荐
- Nginx配置文件(nginx.conf)配置具体解释
欢迎扫码增加Java高知群交流 Nginx的配置文件nginx.conf配置具体解释例如以下: user nginx nginx ; Nginx用户及组:用户 组. window下不指定 wo ...
- js 获取读取cookie
// --- 设置cookie function setCookie(sName, sValue, expireHours) { var cookieString = sName + &quo ...
- HTML-<td> 标签的 valign 属性
<html> <body> <table border="1" style="height:200px"> <tr&g ...
- Java Object Clone
Java Object Clone User user = new User(); user.setName("tom"); User user1 = new User(); us ...
- cognos report利用文本框提示优化日期维度
为了尽量减少手工对日期维度的维护,在日期维度表中年份已经到了2099年,把年份作为下拉框或者月份作为下拉框的时候,选择起来颇为麻烦(当然也可以在此基础之上设置默认为当前月) 如图:提示页面以及html ...
- linux下如何查看所有的用户和组信息?
/etc/group 文件是用户组的配置文件. /etc/passwd 文件是用户的配置文件. 使用cat.more.less.head.tail以及vim等命令都可以查看.修改这两个配置文件. 说 ...
- UE查找和替换技巧实例
1 删除多余的空行 如果是在WORD中,则查找^p^p替换为^p. 如果是在EXCEL里,则为全部选中,然后点击编辑,定位,定位条件,空值. 将全部选中空白的行,如图所示 再次点击编辑,删除,删除整行 ...
- ZH奶酪:JavaScript清空数组的三种方法
参考链接:http://snandy.iteye.com/blog/893955 方式1,length赋值为0 目前 Prototype中数组的 clear 方法和mootools库中数组的 empt ...
- 过滤器(web基础学习笔记二十一)
一.过滤器简介 二.在Eclipse中创建过滤器 三.使用过滤器设置全部web字符编码 public void doFilter(ServletRequest request, ServletResp ...
- request.getSession().setAttribute("",..)和request.setAttribute("",...)的差别
request.getSession.setAttribute()是获得当前会话的session,然后再setAttribute到session里面去,有效范围是session而不是request. ...