RadioButtonList.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. //
  2. // System.Web.UI.WebControls.RadioButtonList.cs
  3. //
  4. // Authors:
  5. // Jordi Mas i Hernandez ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. //
  31. using System.Collections;
  32. using System.ComponentModel;
  33. using System.Collections.Specialized;
  34. namespace System.Web.UI.WebControls {
  35. [ValidationProperty ("SelectedItem")]
  36. public class RadioButtonList : ListControl, IRepeatInfoUser,
  37. INamingContainer, IPostBackDataHandler {
  38. public RadioButtonList ()
  39. {
  40. }
  41. #if ONLY_1_1
  42. [Bindable (true)]
  43. #endif
  44. [DefaultValue (-1)]
  45. [WebSysDescription ("")]
  46. [WebCategory ("Layout")]
  47. public virtual int CellPadding {
  48. get {
  49. if (ControlStyleCreated == false)
  50. return -1; // default value
  51. return ((TableStyle) ControlStyle).CellPadding;
  52. }
  53. set {
  54. ((TableStyle) ControlStyle).CellPadding = value;
  55. }
  56. }
  57. #if ONLY_1_1
  58. [Bindable (true)]
  59. #endif
  60. [DefaultValue (-1)]
  61. [WebSysDescription ("")]
  62. [WebCategory ("Layout")]
  63. public virtual int CellSpacing {
  64. get {
  65. if (ControlStyleCreated == false)
  66. return -1; // default value
  67. return ((TableStyle) ControlStyle).CellSpacing;
  68. }
  69. set {
  70. ((TableStyle) ControlStyle).CellSpacing = value;
  71. }
  72. }
  73. #if ONLY_1_1
  74. [Bindable (true)]
  75. #endif
  76. [DefaultValue (0)]
  77. [WebSysDescription ("")]
  78. [WebCategory ("Layout")]
  79. public virtual int RepeatColumns {
  80. get {
  81. return ViewState.GetInt ("RepeatColumns", 0);
  82. }
  83. set {
  84. if (value < 0)
  85. throw new ArgumentOutOfRangeException ("The number of columns is set to a negative value.");
  86. ViewState ["RepeatColumns"] = value;
  87. }
  88. }
  89. #if ONLY_1_1
  90. [Bindable (true)]
  91. #endif
  92. [DefaultValue (RepeatDirection.Vertical)]
  93. [WebSysDescription ("")]
  94. [WebCategory ("Layout")]
  95. public virtual RepeatDirection RepeatDirection {
  96. get {
  97. return (RepeatDirection) ViewState.GetInt ("RepeatDirection", (int) RepeatDirection.Vertical);
  98. }
  99. set {
  100. if (value != RepeatDirection.Horizontal && value != RepeatDirection.Vertical)
  101. throw new ArgumentOutOfRangeException ("he display direction of the list is not one of the RepeatDirection values.");
  102. ViewState ["RepeatDirection"] = value;
  103. }
  104. }
  105. #if ONLY_1_1
  106. [Bindable (true)]
  107. #endif
  108. [DefaultValue (RepeatLayout.Table)]
  109. [WebSysDescription ("")]
  110. [WebCategory ("Layout")]
  111. public virtual RepeatLayout RepeatLayout {
  112. get {
  113. return (RepeatLayout) ViewState.GetInt ("RepeatLayout", (int) RepeatLayout.Table);
  114. }
  115. set {
  116. if (value != RepeatLayout.Flow && value != RepeatLayout.Table)
  117. throw new ArgumentOutOfRangeException ("The radio buttons layout is not one of the RepeatLayout values.");
  118. ViewState ["RepeatLayout"] = value;
  119. }
  120. }
  121. #if ONLY_1_1
  122. [Bindable (true)]
  123. #endif
  124. [DefaultValue (TextAlign.Right)]
  125. [WebSysDescription ("")]
  126. [WebCategory ("Appearance")]
  127. public virtual TextAlign TextAlign {
  128. get {
  129. return (TextAlign )ViewState.GetInt ("TextAlign", (int) TextAlign.Right);
  130. }
  131. set {
  132. if (value != TextAlign.Left && value != TextAlign.Right)
  133. throw new ArgumentOutOfRangeException ("The label text alignment associated with the radio buttons is not one of the TextAlign values.");
  134. ViewState ["TextAlign"] = value;
  135. }
  136. }
  137. // Interface properties
  138. #if NET_2_0
  139. [MonoTODO]
  140. protected virtual bool HasFooter
  141. {
  142. get {
  143. throw new NotImplementedException ();
  144. }
  145. }
  146. [MonoTODO]
  147. protected virtual bool HasHeader
  148. {
  149. get {
  150. throw new NotImplementedException ();
  151. }
  152. }
  153. [MonoTODO]
  154. protected virtual bool HasSeparators
  155. {
  156. get {
  157. throw new NotImplementedException ();
  158. }
  159. }
  160. [MonoTODO]
  161. protected virtual int RepeatedItemCount
  162. {
  163. get {
  164. throw new NotImplementedException ();
  165. }
  166. }
  167. #endif
  168. bool IRepeatInfoUser.HasFooter {
  169. get { return false; }
  170. }
  171. bool IRepeatInfoUser.HasHeader {
  172. get { return false; }
  173. }
  174. bool IRepeatInfoUser.HasSeparators {
  175. get { return false; }
  176. }
  177. int IRepeatInfoUser.RepeatedItemCount {
  178. get { return Items.Count; }
  179. }
  180. protected override Style CreateControlStyle ()
  181. {
  182. return new TableStyle (ViewState);
  183. }
  184. #if NET_2_0
  185. [MonoTODO]
  186. protected override Control FindControl (string id, int pathOffset)
  187. {
  188. throw new NotImplementedException ();
  189. }
  190. [MonoTODO]
  191. protected virtual Style GetItemStyle (ListItemType itemType, int repeatIndex)
  192. {
  193. throw new NotImplementedException ();
  194. }
  195. [MonoTODO]
  196. protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
  197. {
  198. throw new NotImplementedException ();
  199. }
  200. [MonoTODO]
  201. protected virtual void RaisePostDataChangedEvent ()
  202. {
  203. throw new NotImplementedException ();
  204. }
  205. [MonoTODO]
  206. protected virtual void RenderItem (ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
  207. {
  208. throw new NotImplementedException ();
  209. }
  210. #endif
  211. [MonoTODO]
  212. bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
  213. {
  214. return true;
  215. }
  216. [MonoTODO]
  217. void IPostBackDataHandler.RaisePostDataChangedEvent ()
  218. {
  219. }
  220. Style IRepeatInfoUser.GetItemStyle (ListItemType itemType, int repeatIndex)
  221. {
  222. return null;
  223. }
  224. void IRepeatInfoUser.RenderItem (ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
  225. {
  226. RadioButton radio = new RadioButton ();
  227. radio.Text = Items [repeatIndex].Text;
  228. radio.ID = ClientID + "_" + repeatIndex;
  229. radio.TextAlign = TextAlign;
  230. radio.GroupName = UniqueID;
  231. radio.Page = Page;
  232. radio.Checked = Items [repeatIndex].Selected;
  233. radio.Attributes["Value"] = Items [repeatIndex].Value;
  234. radio.RenderControl (writer);
  235. }
  236. #if NET_2_0
  237. protected internal
  238. #else
  239. protected
  240. #endif
  241. override void Render (HtmlTextWriter writer)
  242. {
  243. RepeatInfo repeat = new RepeatInfo ();
  244. repeat.RepeatColumns = RepeatColumns;
  245. repeat.RepeatDirection = RepeatDirection;
  246. repeat.RepeatLayout = RepeatLayout;
  247. repeat.RenderRepeater (writer, this, ControlStyle, this);
  248. }
  249. }
  250. }