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 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System
.Collections
.Specialized
;
35 using System
.ComponentModel
;
36 using System
.Globalization
;
40 namespace System
.Web
.UI
.WebControls
42 [ValidationProperty("SelectedItem")]
43 public class RadioButtonList
: ListControl
, IRepeatInfoUser
, INamingContainer
, IPostBackDataHandler
45 private bool selectionIndexChanged
;
46 private short tabIndex
;
48 public RadioButtonList(): base()
50 selectionIndexChanged
= false;
53 [DefaultValue (-1), Bindable (true), WebCategory ("Layout")]
54 [WebSysDescription ("The border left within a RadioButton.")]
55 public virtual int CellPadding
59 if(ControlStyleCreated
)
61 return (int)(((TableStyle
)ControlStyle
).CellPadding
);
67 throw new ArgumentOutOfRangeException ("value", "CellPadding value has to be -1 for 'not set' or > -1.");
68 ((TableStyle
)ControlStyle
).CellPadding
= value;
72 [DefaultValue (-1), Bindable (true), WebCategory ("Layout")]
73 [WebSysDescription ("The border left between RadioButtons.")]
74 public virtual int CellSpacing
78 if(ControlStyleCreated
)
80 return (int)(((TableStyle
)ControlStyle
).CellSpacing
);
86 throw new ArgumentOutOfRangeException ("value", "CellSpacing value has to be -1 for 'not set' or > -1.");
87 ((TableStyle
)ControlStyle
).CellSpacing
= value;
91 [DefaultValue (0), Bindable (true), WebCategory ("Layout")]
92 [WebSysDescription ("The number of columns that should be used to display the RadioButtons.")]
93 public virtual int RepeatColumns
97 object o
= ViewState
["RepeatColumns"];
104 throw new ArgumentOutOfRangeException ("value", "RepeatColumns value has to be 0 for 'not set' or > 0.");
105 ViewState
["RepeatColumns"] = value;
109 [DefaultValue (typeof (RepeatDirection
), "Vertical"), Bindable (true), WebCategory ("Layout")]
110 [WebSysDescription ("The direction that is followed when doing the layout.")]
111 public virtual RepeatDirection RepeatDirection
115 object o
= ViewState
["RepeatDirection"];
117 return (RepeatDirection
)o
;
118 return RepeatDirection
.Vertical
;
122 if(!Enum
.IsDefined(typeof(RepeatDirection
), value))
123 throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
124 ViewState
["RepeatDirection"] = value;
128 [DefaultValue (typeof (RepeatLayout
), "Table"), Bindable (true), WebCategory ("Layout")]
129 [WebSysDescription ("The method used to create the layout.")]
130 public virtual RepeatLayout RepeatLayout
134 object o
= ViewState
["RepeatLayout"];
136 return (RepeatLayout
)o
;
137 return RepeatLayout
.Table
;
141 if(!Enum
.IsDefined(typeof(RepeatLayout
), value))
142 throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
143 ViewState
["RepeatLayout"] = value;
147 [DefaultValue (typeof (TextAlign
), "Right"), Bindable (true), WebCategory ("Appearance")]
148 [WebSysDescription ("The alignment of the RadioButton text.")]
149 public virtual TextAlign TextAlign
153 object o
= ViewState
["TextAlign"];
156 return TextAlign
.Right
;
160 if(!Enum
.IsDefined(typeof(TextAlign
), value))
161 throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
162 ViewState
["TextAlign"] = value;
166 protected override Style
CreateControlStyle()
168 return new TableStyle(ViewState
);
171 protected override void Render(HtmlTextWriter writer
)
173 RepeatInfo info
= new RepeatInfo();
174 Style cStyle
= (ControlStyleCreated
? ControlStyle
: null);
179 dirty
= !ViewState
.IsItemDirty("TabIndex");
182 info
.RepeatColumns
= RepeatColumns
;
183 info
.RepeatDirection
= RepeatDirection
;
184 info
.RepeatLayout
= RepeatLayout
;
185 info
.RenderRepeater(writer
, this, cStyle
, this);
192 ViewState
.SetItemDirty("TabIndex", false);
196 bool IPostBackDataHandler
.LoadPostData(string postDataKey
, NameValueCollection postCollection
)
198 string value = postCollection
[postDataKey
];
200 for (int i
= 0; i
< c
; i
++) {
201 if (Items
[i
].Value
!= value)
204 if (i
!= SelectedIndex
) {
206 selectionIndexChanged
= true;
215 void IPostBackDataHandler
.RaisePostDataChangedEvent()
217 if(selectionIndexChanged
)
218 OnSelectedIndexChanged(EventArgs
.Empty
);
221 Style IRepeatInfoUser
.GetItemStyle(System
.Web
.UI
.WebControls
.ListItemType itemType
, int repeatIndex
)
226 void IRepeatInfoUser
.RenderItem (System
.Web
.UI
.WebControls
.ListItemType itemType
,
228 RepeatInfo repeatInfo
,
229 HtmlTextWriter writer
)
231 /* Create a new RadioButton as if it was defined in the page and render it */
232 RadioButton button
= new RadioButton ();
234 button
.GroupName
= UniqueID
;
235 button
.TextAlign
= TextAlign
;
236 button
.AutoPostBack
= AutoPostBack
;
237 button
.ID
= ClientID
+ "_" + repeatIndex
.ToString (NumberFormatInfo
.InvariantInfo
);;
238 button
.TabIndex
= tabIndex
;
239 ListItem current
= Items
[repeatIndex
];
240 button
.Text
= current
.Text
;
241 button
.Attributes
["value"] = current
.Value
;
242 button
.Checked
= current
.Selected
;
243 button
.Enabled
= Enabled
;
244 button
.RenderControl (writer
);
247 bool IRepeatInfoUser
.HasFooter
255 bool IRepeatInfoUser
.HasHeader
263 bool IRepeatInfoUser
.HasSeparators
271 int IRepeatInfoUser
.RepeatedItemCount