[go: up one dir, main page]

0% found this document useful (0 votes)
120 views3 pages

Web Control: The Radio Button List

The document discusses the radio button list web control in ASP.NET, including how to create one with items, set captions for the radio buttons, and align the captions.

Uploaded by

BaneeIshaqueK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views3 pages

Web Control: The Radio Button List

The document discusses the radio button list web control in ASP.NET, including how to create one with items, set captions for the radio buttons, and align the captions.

Uploaded by

BaneeIshaqueK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

7/4/2015

ASP.NETWebControl:TheRadioButtonList

WebControl:TheRadioButtonList

RadioButtonListFundamentals

Introduction
Toassistyouwithcreatingagroupofradiobuttons,youcanusetheRadioButtonListcontrol.
This control is implemented by the RadioButtonList class defined in the
System.Web.UI.WebControlsnamespaceoftheSystem.Web.dllassembly.

CreatingaRadioButtonList
Tovisuallycreatearadiobuttonlist,fromtheStandardsectionoftheToolbox,youcandrag
RadioButtonListanddropitontheform.Youwouldbeaskedtocreateeachitemofthegroup.
Todothis,youcanclickitsarrowbuttonandclickEditItems,thenusetheListItemCollection
Editor:

Iftheradiobuttonlistwasalreadycreated,toaccesstheListItemCollectionEditor,clickthe
radiobuttonlistontheform.InthePropertieswindow,clickItemsandclickbrowsebutton.
Tomanuallycreateagroupofradiobuttons,createan<asp:RadioButtonList>tagonthe
form:
<%@PageLanguage="C#"%>
<html>
<head>
<title>Exercise</title>
</head>
<body>
<h3>Exercise</h3>
<formid="frmRealEstate"method="post"runat="server">
<asp:RadioButtonListid="Genders"runat="server"></asp:RadioButtonList>
</form>
</body>
</html>

Tocreateeachitemofthegroup,
IfyouareusingtheListItemCollectionEditor,clickAdd

Ifyouareworkingmanually,betweentheopeningandtheclosingtags,createan
asp:ListItemtagwithitsownstartingandclosingtags:

<%@PageLanguage="C#"%>
<html>
<head>
<title>Exercise</title>
</head>

http://www.csharpkey.com/aspnet/controls/radiobuttonlist.htm

1/3

7/4/2015

ASP.NETWebControl:TheRadioButtonList

<body>

<formid="frmRealEstate"method="post"runat="server">
<asp:RadioButtonListid="Genders"runat="server">
<asp:ListItem></asp:ListItem>
</asp:RadioButtonList>
</form>
</body>
</html>

CharacteristicsofaRadioButtonList

TheCaptionsofRadioButtons
Obviouseachradiobuttonshoulddisplaytexttoshowwhatitisusedfor:
IfyouareworkingintheListItemCollectionEditor,ontheleftside,clickanitem.Onthe
rightside,clickTextandtypethedesiredstring
Ifyouareworkingmanually,tospecifythecaptionofaradiobutton,typeitsstring
betweenthebeginningandtheendingtags

Hereareexamples:

<%@PageLanguage="C#"%>
<html>
<head>
<title>Exercise</title>
</head>
<body>
<formid="frmRealEstate"method="post"runat="server">
<asp:RadioButtonListid="Genders"runat="server">
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
<asp:ListItem>Unknown</asp:ListItem>
</asp:RadioButtonList>
</form>
</body>
</html>

Thiswouldproduce:

TheCaptionAlignmentofaRadioButton
By default, the captions of the radio buttons are positioned on the right side of their round
boxes. This characteristic is controlled by the TextAlign attribute of the RadioButtonList
controlandwhosedefaultvalueisRight.Ifyouwantthecaptionstobepositionedtotheleft,
assigntheLeftstringtothisattribute.Hereisanexample:
<%@PageLanguage="C#"%>
<html>
<head>
<title>Exercise</title>
</head>
<body>

http://www.csharpkey.com/aspnet/controls/radiobuttonlist.htm

2/3

7/4/2015

ASP.NETWebControl:TheRadioButtonList

<formid="frmRealEstate"method="post"runat="server">
<asp:RadioButtonListid="Genders"TextAlign="Left"runat="server">
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
<asp:ListItem>Unknown</asp:ListItem>
</asp:RadioButtonList>
</form>

</body>
</html>

Thiswouldproduce:

Home

Copyright20092011C#Key

http://www.csharpkey.com/aspnet/controls/radiobuttonlist.htm

3/3

You might also like