RadioButtonList.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: RadioButtonList
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Implementation: yes
  9. * Status: 95%
  10. *
  11. * (C) Gaurav Vaish (2002)
  12. */
  13. using System;
  14. using System.Collections.Specialized;
  15. using System.Web;
  16. using System.Web.UI;
  17. namespace System.Web.UI.WebControls
  18. {
  19. [ValidationProperty("SelectedItem")]
  20. public class RadioButtonList : ListControl, IRepeatInfoUser, INamingContainer, IPostBackDataHandler
  21. {
  22. private bool selectionIndexChanged;
  23. private short tabIndex;
  24. public RadioButtonList(): base()
  25. {
  26. selectionIndexChanged = false;
  27. }
  28. public virtual int CellPadding
  29. {
  30. get
  31. {
  32. if(ControlStyleCreated)
  33. {
  34. return (int)(((TableStyle)ControlStyle).CellPadding);
  35. }
  36. return -1;
  37. }
  38. set
  39. {
  40. ((TableStyle)ControlStyle).CellPadding = value;
  41. }
  42. }
  43. public virtual int CellSpacing
  44. {
  45. get
  46. {
  47. if(ControlStyleCreated)
  48. {
  49. return (int)(((TableStyle)ControlStyle).CellSpacing);
  50. }
  51. return -1;
  52. }
  53. set
  54. {
  55. ((TableStyle)ControlStyle).CellSpacing = value;
  56. }
  57. }
  58. public virtual int RepeatColumns
  59. {
  60. get
  61. {
  62. object o = ViewState["RepeatColumns"];
  63. if(o != null)
  64. return (int)o;
  65. return 0;
  66. }
  67. set
  68. {
  69. if(value < 0)
  70. throw new ArgumentOutOfRangeException("value");
  71. ViewState["RepeatColumns"] = value;
  72. }
  73. }
  74. public virtual RepeatDirection RepeatDirection
  75. {
  76. get
  77. {
  78. object o = ViewState["RepeatDirection"];
  79. if(o != null)
  80. return (RepeatDirection)o;
  81. return RepeatDirection.Vertical;
  82. }
  83. set
  84. {
  85. if(!Enum.IsDefined(typeof(RepeatDirection), value))
  86. throw new ArgumentException();
  87. ViewState["RepeatDirection"] = value;
  88. }
  89. }
  90. public virtual RepeatLayout RepeatLayout
  91. {
  92. get
  93. {
  94. object o = ViewState["RepeatLayout"];
  95. if(o != null)
  96. return (RepeatLayout)o;
  97. return RepeatLayout.Table;
  98. }
  99. set
  100. {
  101. if(!Enum.IsDefined(typeof(RepeatLayout), value))
  102. throw new ArgumentException();
  103. ViewState["RepeatLayout"] = value;
  104. }
  105. }
  106. public virtual TextAlign TextAlign
  107. {
  108. get
  109. {
  110. object o = ViewState["TextAlign"];
  111. if(o != null)
  112. return (TextAlign)o;
  113. return TextAlign.Right;
  114. }
  115. set
  116. {
  117. if(!Enum.IsDefined(typeof(TextAlign), value))
  118. throw new ArgumentException();
  119. ViewState["TextAlign"] = value;
  120. }
  121. }
  122. protected override Style CreateControlStyle()
  123. {
  124. return new TableStyle(ViewState);
  125. }
  126. protected override void Render(HtmlTextWriter writer)
  127. {
  128. RepeatInfo info = new RepeatInfo();
  129. Style cStyle = (ControlStyleCreated ? ControlStyle : null);
  130. bool dirty = false;
  131. tabIndex = TabIndex;
  132. if(tabIndex != 0)
  133. {
  134. dirty = !ViewState.IsItemDirty("TabIndex");
  135. TabIndex = 0;
  136. }
  137. info.RepeatColumns = RepeatColumns;
  138. info.RepeatDirection = RepeatDirection;
  139. info.RenderRepeater(writer, this, cStyle, this);
  140. if(tabIndex != 0)
  141. {
  142. TabIndex = tabIndex;
  143. }
  144. if(dirty)
  145. {
  146. ViewState.SetItemDirty("TabIndex", false);
  147. }
  148. }
  149. bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
  150. {
  151. string value = postCollection[postDataKey];
  152. for(int i=0; i < Items.Count; i++)
  153. {
  154. if(Items[i].Value == value)
  155. {
  156. if(i != SelectedIndex)
  157. {
  158. SelectedIndex = i;
  159. }
  160. return true;
  161. }
  162. }
  163. return false;
  164. }
  165. void IPostBackDataHandler.RaisePostDataChangedEvent()
  166. {
  167. if(selectionIndexChanged)
  168. OnSelectedIndexChanged(EventArgs.Empty);
  169. }
  170. Style IRepeatInfoUser.GetItemStyle(System.Web.UI.WebControls.ListItemType itemType, int repeatIndex)
  171. {
  172. return null;
  173. }
  174. [MonoTODO("RadioButtonList_RenderItem")]
  175. void IRepeatInfoUser.RenderItem(System.Web.UI.WebControls.ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
  176. {
  177. throw new NotImplementedException();
  178. }
  179. bool IRepeatInfoUser.HasFooter
  180. {
  181. get
  182. {
  183. return false;
  184. }
  185. }
  186. bool IRepeatInfoUser.HasHeader
  187. {
  188. get
  189. {
  190. return false;
  191. }
  192. }
  193. bool IRepeatInfoUser.HasSeparators
  194. {
  195. get
  196. {
  197. return false;
  198. }
  199. }
  200. int IRepeatInfoUser.RepeatedItemCount
  201. {
  202. get
  203. {
  204. return Items.Count;
  205. }
  206. }
  207. }
  208. }