2 // System.Web.UI.WebControls.RadioButtonList.cs
5 // Jordi Mas i Hernandez (jordi@ximian.com)
7 // (C) 2005 Novell, Inc (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
32 using System.Collections;
33 using System.ComponentModel;
34 using System.Collections.Specialized;
36 namespace System.Web.UI.WebControls {
38 [ValidationProperty ("SelectedItem")]
39 public class RadioButtonList : ListControl, IRepeatInfoUser,
40 INamingContainer, IPostBackDataHandler {
42 public RadioButtonList ()
51 [WebSysDescription ("")]
52 [WebCategory ("Layout")]
53 public virtual int CellPadding {
55 if (ControlStyleCreated == false)
56 return -1; // default value
58 return ((TableStyle) ControlStyle).CellPadding;
62 ((TableStyle) ControlStyle).CellPadding = value;
70 [WebSysDescription ("")]
71 [WebCategory ("Layout")]
72 public virtual int CellSpacing {
74 if (ControlStyleCreated == false)
75 return -1; // default value
77 return ((TableStyle) ControlStyle).CellSpacing;
81 ((TableStyle) ControlStyle).CellSpacing = value;
89 [WebSysDescription ("")]
90 [WebCategory ("Layout")]
91 public virtual int RepeatColumns {
93 return ViewState.GetInt ("RepeatColumns", 0);
98 throw new ArgumentOutOfRangeException ("The number of columns is set to a negative value.");
100 ViewState ["RepeatColumns"] = value;
107 [DefaultValue (RepeatDirection.Vertical)]
108 [WebSysDescription ("")]
109 [WebCategory ("Layout")]
110 public virtual RepeatDirection RepeatDirection {
112 return (RepeatDirection) ViewState.GetInt ("RepeatDirection", (int) RepeatDirection.Vertical);
116 if (value != RepeatDirection.Horizontal && value != RepeatDirection.Vertical)
117 throw new ArgumentOutOfRangeException ("he display direction of the list is not one of the RepeatDirection values.");
119 ViewState ["RepeatDirection"] = value;
126 [DefaultValue (RepeatLayout.Table)]
127 [WebSysDescription ("")]
128 [WebCategory ("Layout")]
129 public virtual RepeatLayout RepeatLayout {
131 return (RepeatLayout) ViewState.GetInt ("RepeatLayout", (int) RepeatLayout.Table);
135 if (value != RepeatLayout.Flow && value != RepeatLayout.Table)
136 throw new ArgumentOutOfRangeException ("The radio buttons layout is not one of the RepeatLayout values.");
138 ViewState ["RepeatLayout"] = value;
145 [DefaultValue (TextAlign.Right)]
146 [WebSysDescription ("")]
147 [WebCategory ("Appearance")]
148 public virtual TextAlign TextAlign {
150 return (TextAlign )ViewState.GetInt ("TextAlign", (int) TextAlign.Right);
154 if (value != TextAlign.Left && value != TextAlign.Right)
155 throw new ArgumentOutOfRangeException ("The label text alignment associated with the radio buttons is not one of the TextAlign values.");
157 ViewState ["TextAlign"] = value;
161 // Interface properties
165 protected virtual bool HasFooter
168 throw new NotImplementedException ();
173 protected virtual bool HasHeader
176 throw new NotImplementedException ();
181 protected virtual bool HasSeparators
184 throw new NotImplementedException ();
189 protected virtual int RepeatedItemCount
192 throw new NotImplementedException ();
197 bool IRepeatInfoUser.HasFooter {
198 get { return false; }
201 bool IRepeatInfoUser.HasHeader {
202 get { return false; }
205 bool IRepeatInfoUser.HasSeparators {
206 get { return false; }
209 int IRepeatInfoUser.RepeatedItemCount {
210 get { return Items.Count; }
213 protected override Style CreateControlStyle ()
215 return new TableStyle (ViewState);
220 protected override Control FindControl (string id, int pathOffset)
222 throw new NotImplementedException ();
229 Style GetItemStyle (ListItemType itemType, int repeatIndex)
237 void RenderItem (ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
239 RadioButton radio = new RadioButton ();
240 radio.Text = Items [repeatIndex].Text;
241 radio.ID = ClientID + "_" + repeatIndex;
242 radio.TextAlign = TextAlign;
243 radio.GroupName = UniqueID;
245 radio.Checked = Items [repeatIndex].Selected;
246 radio.Attributes["Value"] = Items [repeatIndex].Value;
247 radio.RenderControl (writer);
254 bool LoadPostData (string postDataKey, NameValueCollection postCollection)
263 void RaisePostDataChangedEvent ()
268 bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
270 return LoadPostData (postDataKey, postCollection);
273 void IPostBackDataHandler.RaisePostDataChangedEvent ()
275 RaisePostDataChangedEvent ();
278 Style IRepeatInfoUser.GetItemStyle (ListItemType itemType, int repeatIndex)
280 return GetItemStyle (itemType, repeatIndex);
283 void IRepeatInfoUser.RenderItem (ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
285 RenderItem (itemType, repeatIndex, repeatInfo, writer);
293 override void Render (HtmlTextWriter writer)
295 RepeatInfo repeat = new RepeatInfo ();
296 repeat.RepeatColumns = RepeatColumns;
297 repeat.RepeatDirection = RepeatDirection;
298 repeat.RepeatLayout = RepeatLayout;
299 repeat.RenderRepeater (writer, this, ControlStyle, this);