2 // System.Web.UI.WebControls.RadioButtonList.cs
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
13 using System.Collections.Specialized;
\r
14 using System.ComponentModel;
\r
15 using System.Globalization;
\r
17 using System.Web.UI;
\r
19 namespace System.Web.UI.WebControls
\r
21 [ValidationProperty("SelectedItem")]
\r
22 public class RadioButtonList : ListControl, IRepeatInfoUser, INamingContainer, IPostBackDataHandler
\r
24 private bool selectionIndexChanged;
\r
25 private short tabIndex;
\r
27 public RadioButtonList(): base()
\r
29 selectionIndexChanged = false;
\r
32 [DefaultValue (-1), Bindable (true), WebCategory ("Layout")]
33 [WebSysDescription ("The border left within a RadioButton.")]
\r
34 public virtual int CellPadding
\r
38 if(ControlStyleCreated)
\r
40 return (int)(((TableStyle)ControlStyle).CellPadding);
\r
46 throw new ArgumentOutOfRangeException ("value", "CellPadding value has to be -1 for 'not set' or > -1.");
\r
47 ((TableStyle)ControlStyle).CellPadding = value;
\r
51 [DefaultValue (-1), Bindable (true), WebCategory ("Layout")]
52 [WebSysDescription ("The border left between RadioButtons.")]
\r
53 public virtual int CellSpacing
\r
57 if(ControlStyleCreated)
\r
59 return (int)(((TableStyle)ControlStyle).CellSpacing);
\r
65 throw new ArgumentOutOfRangeException ("value", "CellSpacing value has to be -1 for 'not set' or > -1.");
\r
66 ((TableStyle)ControlStyle).CellSpacing = value;
\r
70 [DefaultValue (0), Bindable (true), WebCategory ("Layout")]
71 [WebSysDescription ("The number of columns that should be used to display the RadioButtons.")]
\r
72 public virtual int RepeatColumns
\r
76 object o = ViewState["RepeatColumns"];
\r
83 throw new ArgumentOutOfRangeException ("value", "RepeatColumns value has to be 0 for 'not set' or > 0.");
\r
84 ViewState["RepeatColumns"] = value;
\r
88 [DefaultValue (typeof (RepeatDirection), "Vertical"), Bindable (true), WebCategory ("Layout")]
89 [WebSysDescription ("The direction that is followed when doing the layout.")]
\r
90 public virtual RepeatDirection RepeatDirection
\r
94 object o = ViewState["RepeatDirection"];
\r
96 return (RepeatDirection)o;
\r
97 return RepeatDirection.Vertical;
\r
101 if(!Enum.IsDefined(typeof(RepeatDirection), value))
\r
102 throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
\r
103 ViewState["RepeatDirection"] = value;
\r
107 [DefaultValue (typeof (RepeatLayout), "Table"), Bindable (true), WebCategory ("Layout")]
108 [WebSysDescription ("The method used to create the layout.")]
\r
109 public virtual RepeatLayout RepeatLayout
\r
113 object o = ViewState["RepeatLayout"];
\r
115 return (RepeatLayout)o;
\r
116 return RepeatLayout.Table;
\r
120 if(!Enum.IsDefined(typeof(RepeatLayout), value))
\r
121 throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
\r
122 ViewState["RepeatLayout"] = value;
\r
126 [DefaultValue (typeof (TextAlign), "Right"), Bindable (true), WebCategory ("Appearance")]
127 [WebSysDescription ("The alignment of the RadioButton text.")]
\r
128 public virtual TextAlign TextAlign
\r
132 object o = ViewState["TextAlign"];
\r
134 return (TextAlign)o;
\r
135 return TextAlign.Right;
\r
139 if(!Enum.IsDefined(typeof(TextAlign), value))
\r
140 throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
\r
141 ViewState["TextAlign"] = value;
\r
145 protected override Style CreateControlStyle()
\r
147 return new TableStyle(ViewState);
\r
150 protected override void Render(HtmlTextWriter writer)
\r
152 RepeatInfo info = new RepeatInfo();
\r
153 Style cStyle = (ControlStyleCreated ? ControlStyle : null);
\r
154 bool dirty = false;
\r
155 tabIndex = TabIndex;
\r
158 dirty = !ViewState.IsItemDirty("TabIndex");
\r
161 info.RepeatColumns = RepeatColumns;
\r
162 info.RepeatDirection = RepeatDirection;
\r
163 info.RepeatLayout = RepeatLayout;
\r
164 info.RenderRepeater(writer, this, cStyle, this);
\r
167 TabIndex = tabIndex;
\r
171 ViewState.SetItemDirty("TabIndex", false);
\r
175 bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
177 string value = postCollection [postDataKey];
179 for (int i = 0; i < c; i++) {
180 if (Items [i].Value != value)
183 if (i != SelectedIndex) {
185 selectionIndexChanged = true;
194 void IPostBackDataHandler.RaisePostDataChangedEvent()
\r
196 if(selectionIndexChanged)
\r
197 OnSelectedIndexChanged(EventArgs.Empty);
\r
200 Style IRepeatInfoUser.GetItemStyle(System.Web.UI.WebControls.ListItemType itemType, int repeatIndex)
\r
205 void IRepeatInfoUser.RenderItem (System.Web.UI.WebControls.ListItemType itemType,
\r
207 RepeatInfo repeatInfo,
\r
208 HtmlTextWriter writer)
\r
210 /* Create a new RadioButton as if it was defined in the page and render it */
\r
211 RadioButton button = new RadioButton ();
\r
213 button.GroupName = UniqueID;
\r
214 button.TextAlign = TextAlign;
\r
215 button.AutoPostBack = AutoPostBack;
\r
216 button.ID = ClientID + "_" + repeatIndex.ToString (NumberFormatInfo.InvariantInfo);;
\r
217 button.TabIndex = tabIndex;
218 ListItem current = Items [repeatIndex];
\r
219 button.Text = current.Text;
\r
220 button.Attributes ["value"] = current.Value;
\r
221 button.Checked = current.Selected;
\r
222 button.Enabled = Enabled;
\r
223 button.RenderControl (writer);
\r
226 bool IRepeatInfoUser.HasFooter
\r
234 bool IRepeatInfoUser.HasHeader
\r
242 bool IRepeatInfoUser.HasSeparators
\r
250 int IRepeatInfoUser.RepeatedItemCount
\r
254 return Items.Count;
\r