RadioButtonList.cs 4.4 KB

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