Radiobutton实现单选。

  1   using  System;
  2   using  System.Web.UI;
  3   using  System.Web.UI.WebControls;
  4   using  System.Globalization;
  5  
  6   namespace  Renyu.Web.UI.WebControls
  7   {
  8       [ToolboxData( " <{0}:GroupRadioButton runat=server></{0}:GroupRadioButton> " )]
  9        public   class  GroupRadioButton : RadioButton, IPostBackDataHandler
 10       {
 11            public  GroupRadioButton() :  base ()
 12           {
 13           }
 14  
 15            #region  Properties
 16  
 17            private   string  Value
 18           {
 19                get
 20               {
 21                    string  val  =  Attributes[ " value " ];
 22                    if (val  ==   null )
 23                       val  =  UniqueID;
 24                    else
 25                       val  =  UniqueID  +   " _ "   +  val;
 26                    return  val;
 27               }
 28           }
 29  
 30            #endregion
 31           
 32            #region  Rendering
 33  
 34            protected   override   void  Render(HtmlTextWriter output)
 35           {
 36               RenderInputTag(output);
 37           }
 38  
 39            private   void  RenderInputTag(HtmlTextWriter htw)
 40           {
 41               htw.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
 42               htw.AddAttribute(HtmlTextWriterAttribute.Type,  " radio " );
 43               htw.AddAttribute(HtmlTextWriterAttribute.Name, GroupName);
 44               htw.AddAttribute(HtmlTextWriterAttribute.Value, Value);
 45                if (Checked)
 46                   htw.AddAttribute(HtmlTextWriterAttribute.Checked,  " checked " );
 47                if ( ! Enabled)
 48                   htw.AddAttribute(HtmlTextWriterAttribute.Disabled,  " disabled " );
 49               
 50                string  onClick  =  Attributes[ " onclick " ];
 51                if (AutoPostBack)
 52               {
 53                    if (onClick  !=   null )
 54                       onClick  =  String.Empty;
 55                   onClick  +=  Page.GetPostBackClientEvent( this , String.Empty);
 56                   htw.AddAttribute(HtmlTextWriterAttribute.Onclick, onClick);
 57                   htw.AddAttribute( " language " " javascript " );
 58               }
 59                else
 60               {
 61                    if (onClick  !=   null )
 62                       htw.AddAttribute(HtmlTextWriterAttribute.Onclick, onClick);
 63               }
 64  
 65                if (AccessKey.Length  >   0 )
 66                   htw.AddAttribute(HtmlTextWriterAttribute.Accesskey, AccessKey);
 67                if (TabIndex  !=   0 )
 68                   htw.AddAttribute(HtmlTextWriterAttribute.Tabindex, 
 69                       TabIndex.ToString(NumberFormatInfo.InvariantInfo));
 70               htw.RenderBeginTag(HtmlTextWriterTag.Input);
 71               htw.RenderEndTag();
 72           }
 73  
 74            #endregion
 75  
 76            #region  IPostBackDataHandler Members
 77  
 78            void  IPostBackDataHandler.RaisePostDataChangedEvent()
 79           {
 80               OnCheckedChanged(EventArgs.Empty);
 81           }
 82  
 83            bool  IPostBackDataHandler.LoadPostData( string  postDataKey, 
 84               System.Collections.Specialized.NameValueCollection postCollection)
 85           {
 86                bool  result  =   false ;
 87                string  value  =  postCollection[GroupName];
 88                if ((value  !=   null &&  (value  ==  Value))
 89               {
 90                    if ( ! Checked)
 91                   {
 92                       Checked  =   true ;
 93                       result  =   true ;
 94                   }
 95               }
 96                else
 97               {
 98                    if (Checked)
 99                       Checked  =   false ;
100               }
101                return  result;
102           }
103  
104            #endregion
105       }

106 }




原文摘自:http://www.cnblogs.com/renyu732/archive/2005/12/17/298991.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值