扩展Asp.net中的DropDownList

   在Asp.net用户控件设计中,有时需要对某个DropDownList,和当些控件的文字进行操作。例如,隐藏。
把文字设成LABEL可解决,但我们可以把文件包含到控件中。对DropDownList进行扩展,举一反三
可以扩展其它控件,可以也增加其它属性,如Css样式。具体代码如下:
 1       #region  XDropDownList
 2       ///   <summary>
 3       ///  辅助的XDropDownList
 4       ///   <remarks> 便于组件中隐藏控件,文字与控件同时进行控制。
 5       ///  Author:Petter Liu   http://wintersun.cnblogs.com
 6       ///   </remarks>
 7       ///   <example>
 8       ///   <![CDATA[
 9       ///   <%@ Register Assembly="Utility" Namespace="Utility.Controls" TagPrefix="diycontrol" %>
10       ///   <diycontrol:XDropDownList ID="DdlProduct" runat="server" FrontText="产品一:" Width="120px" />
11       ///  ]]>
12       ///   </example>
13       ///   </summary>
14      [AspNetHostingPermission(SecurityAction.Demand,
15      Level  =  AspNetHostingPermissionLevel.Minimal),
16      AspNetHostingPermission(SecurityAction.InheritanceDemand,
17      Level  =  AspNetHostingPermissionLevel.Minimal),
18      DefaultProperty( " FrontText " ),
19      ToolboxData( " <{0}:XDropDownList runat=\ " server\ " > </{0}:XDropDownList> " )]
20       public   class  XDropDownList : DropDownList
21      {
22           #region  Properties
23           ///   <summary>
24           ///  Gets or sets the front text.
25           ///   </summary>
26           ///   <value> The front text. </value>
27          [Bindable( true ),
28          Category( " Appearance " ),
29          DefaultValue( "" ),
30          Description( " Before DropDownList Text " ),
31          Localizable( true )]
32           public   virtual   string  FrontText
33          {
34               get
35              {
36                   string  s  =  ( string )ViewState[ " FrontText " ];
37                   return  (s  ==   null ?  String.Empty : s;
38              }
39               set
40              {
41                  ViewState[ " FrontText " =  value;
42              }
43          }
44           #endregion
45 
46           #region  override void RenderBeginTag(HtmlTextWriter writer)
47           ///   <summary>
48           ///  Renders the HTML opening tag of the control to the specified writer. This method is used primarily by control developers.
49           ///   </summary>
50           ///   <param name="writer"> <see cref="T:System.Web.UI.HtmlTextWriter"></see>  that represents the output stream to render HTML content on the client. </param>
51           public   override   void  RenderBeginTag(HtmlTextWriter writer)
52          {
53               if  ( ! string .IsNullOrEmpty(FrontText))
54                  writer.Write(FrontText);
55               base .RenderBeginTag(writer);
56          }
57           #endregion
58      }
59       #endregion
http://www.cnblogs.com/wintersun
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值