RadioButtonList.cs 4.4 KB

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