RadioButtonList 웹 서버 컨트롤 선언 구문
업데이트: 2007년 11월
라디오 단추의 그룹을 만드는 데 사용하는 컨트롤입니다. 이 컨트롤에서는 데이터 소스에 대한 바인딩을 지원합니다.
<asp:RadioButtonList
AccessKey="string"
AppendDataBoundItems="True|False"
AutoPostBack="True|False"
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
Inset|Outset"
BorderWidth="size"
CausesValidation="True|False"
CellPadding="integer"
CellSpacing="integer"
CssClass="string"
DataMember="string"
DataSource="string"
DataSourceID="string"
DataTextField="string"
DataTextFormatString="string"
DataValueField="string"
Enabled="True|False"
EnableTheming="True|False"
EnableViewState="True|False"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
ID="string"
OnDataBinding="DataBinding event handler"
OnDataBound="DataBound event handler"
OnDisposed="Disposed event handler"
OnInit="Init event handler"
OnLoad="Load event handler"
OnPreRender="PreRender event handler"
OnSelectedIndexChanged="SelectedIndexChanged event handler"
OnTextChanged="TextChanged event handler"
OnUnload="Unload event handler"
RepeatColumns="integer"
RepeatDirection="Horizontal|Vertical"
RepeatLayout="Table|Flow"
runat="server"
SelectedIndex="integer"
SelectedValue="string"
SkinID="string"
Style="string"
TabIndex="integer"
TextAlign="Left|Right"
ToolTip="string"
ValidationGroup="string"
Visible="True|False"
Width="size"
>
<asp:ListItem
Enabled="True|False"
Selected="True|False"
Text="string"
Value="string"
/>
</asp:RadioButtonList>
설명
RadioButtonList 컨트롤을 사용하면 데이터 소스에 바인딩하여 동적으로 생성할 수 있는 단일 선택 라디오 단추 그룹을 만들 수 있습니다. RadioButtonList 컨트롤에 표시할 항목을 지정하려면 각 항목에 대한 ListItem 요소를 RadioButtonList 컨트롤의 여는 태그와 닫는 태그 사이에 추가합니다.
참고
RadioButton 컨트롤을 사용할 수도 있습니다. RadioButtonList 컨트롤을 사용하면 데이터 바인딩을 사용하여 좀 더 쉽게 라디오 단추 집합을 만들 수 있고 개별 RadioButton 컨트롤을 사용하면 레이아웃을 세밀하게 제어할 수 있다는 이점이 있습니다.
RadioButtonList 컨트롤에서는 데이터 바인딩도 지원합니다. 컨트롤을 데이터 소스에 바인딩하려면 먼저 컨트롤에 표시할 항목이 포함된 데이터 소스(예: ArrayList 개체)를 만듭니다. 그런 다음 DataBind 메서드를 사용하여 데이터 소스를 RadioButtonList 컨트롤에 바인딩합니다. DataTextField 및 DataValueField 속성을 사용하면 컨트롤에 있는 각 목록 항목의 Text 속성과 Value 속성에 각각 바인딩할 데이터 소스 필드를 지정할 수 있습니다. 그러면 RadioButtonList 컨트롤에서는 데이터 소스에서 가져온 정보를 표시합니다.
RadioButtonList 컨트롤에서 선택된 항목을 확인하려면 Items 컬렉션을 반복하면서 컬렉션에 포함된 각 항목의 Selected 속성을 테스트합니다.
RepeatLayout 및 RepeatDirection 속성을 사용하여 목록의 렌더링을 지정할 수 있습니다. RepeatLayout이 Table(기본 설정)로 설정되면 표 내에서 목록이 렌더링됩니다. 이 속성이 Flow로 설정되면 표 형식의 구조를 사용하지 않고 목록이 렌더링됩니다. 기본적으로 RepeatDirection는 Vertical로 설정됩니다. 이 속성을 Horizontal로 설정하면 목록이 가로로 렌더링됩니다.
경고
텍스트는 RadioButtonList 컨트롤에 표시된 후에 HTML로 인코딩됩니다. 따라서 텍스트의 HTML 태그 내에 스크립트를 포함시킬 수 있습니다. 컨트롤 값을 사용자 입력에서 가져온 경우 값이 유효한지 확인하여 보안상의 허점을 방지합니다.
RadioButtonList 웹 서버 컨트롤의 속성과 이벤트에 대한 자세한 내용은 RadioButtonList 클래스 설명서를 참조하십시오.
예제
다음 예제에서는 RadioButtonList 컨트롤을 사용하여 한 번에 하나만 선택할 수 있는 옵션 집합을 사용자에게 표시하는 방법을 보여 줍니다.
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>RadioButtonList Example</title>
<script language="VB" runat="server">
Sub Button1_Click(Source As Object, e As EventArgs)
If RadioButtonList1.SelectedIndex > - 1 Then
Label1.Text = "You selected: " & RadioButtonList1.SelectedItem.Text
End If
End Sub
Sub chkLayout_CheckedChanged(sender As Object, e As EventArgs)
If chkLayout.Checked = True Then
RadioButtonList1.RepeatLayout = RepeatLayout.Table
Else
RadioButtonList1.RepeatLayout = RepeatLayout.Flow
End If
End Sub
Sub chkDirection_CheckedChanged(sender As Object, e As EventArgs)
If chkDirection.Checked = True Then
RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal
Else
RadioButtonList1.RepeatDirection = RepeatDirection.Vertical
End If
End Sub
</script>
</head>
<body>
<h3>RadioButtonList Example</h3>
<form id="form1" runat="server">
<asp:RadioButtonList id="RadioButtonList1" runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:CheckBox id="chkLayout" OnCheckedChanged="chkLayout_CheckedChanged" Text="Display Table Layout" Checked="true" AutoPostBack="true" runat="server" />
<br />
<asp:CheckBox id="chkDirection" OnCheckedChanged="chkDirection_CheckedChanged" Text="Display Horizontally" AutoPostBack="true" runat="server" />
<br />
<asp:Button id="Button1" Text="Submit" onclick="Button1_Click" runat="server"/>
<br />
<asp:Label id="Label1" font-names="Verdana" font-size="8pt" runat="server"/>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>RadioButtonList Example</title>
<script language="C#" runat="server">
void Button1_Click(object Source, EventArgs e)
{
if (RadioButtonList1.SelectedIndex > -1)
{
Label1.Text = "You selected: " + RadioButtonList1.SelectedItem.Text;
}
}
void chkLayout_CheckedChanged(Object sender, EventArgs e)
{
if (chkLayout.Checked == true)
{
RadioButtonList1.RepeatLayout = RepeatLayout.Table;
}
else
{
RadioButtonList1.RepeatLayout = RepeatLayout.Flow;
}
}
void chkDirection_CheckedChanged(Object sender, EventArgs e)
{
if (chkDirection.Checked == true)
{
RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal;
}
else
{
RadioButtonList1.RepeatDirection = RepeatDirection.Vertical;
}
}
</script>
</head>
<body>
<h3>RadioButtonList Example</h3>
<form id="form1" runat="server">
<asp:RadioButtonList id="RadioButtonList1" runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:CheckBox id="chkLayout" OnCheckedChanged="chkLayout_CheckedChanged" Text="Display Table Layout" Checked="true" AutoPostBack="true" runat="server" />
<br />
<asp:CheckBox id="chkDirection" OnCheckedChanged="chkDirection_CheckedChanged" Text="Display Horizontally" AutoPostBack="true" runat="server" />
<br />
<asp:Button id="Button1" Text="Submit" onclick="Button1_Click" runat="server"/>
<br />
<asp:Label id="Label1" font-names="Verdana" font-size="8pt" runat="server"/>
</form>
</body>
</html>
<%@ Page Language="JScript" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>RadioButtonList Example</title>
<script language="JScript" runat="server">
function Button1_Click(Source : System.Object, e : EventArgs)
{
if (RadioButtonList1.SelectedIndex > -1)
{
Label1.Text = "You selected: " + RadioButtonList1.SelectedItem.Text;
}
}
function chkLayout_CheckedChanged(sender : System.Object, e : EventArgs)
{
if (chkLayout.Checked == true)
{
RadioButtonList1.RepeatLayout = RepeatLayout.Table;
}
else
{
RadioButtonList1.RepeatLayout = RepeatLayout.Flow;
}
}
function chkDirection_CheckedChanged(sender : System.Object, e : EventArgs)
{
if (chkDirection.Checked == true)
{
RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal;
}
else
{
RadioButtonList1.RepeatDirection = RepeatDirection.Vertical;
}
}
</script>
</head>
<body>
<h3>RadioButtonList Example</h3>
<form id="form1" runat="server">
<asp:RadioButtonList id="RadioButtonList1" runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:CheckBox id="chkLayout" OnCheckedChanged="chkLayout_CheckedChanged" Text="Display Table Layout" Checked="true" AutoPostBack="true" runat="server" />
<br />
<asp:CheckBox id="chkDirection" OnCheckedChanged="chkDirection_CheckedChanged" Text="Display Horizontally" AutoPostBack="true" runat="server" />
<br />
<asp:Button id="Button1" Text="Submit" onclick="Button1_Click" runat="server"/>
<br />
<asp:Label id="Label1" font-name="Verdana" font-size="8pt" runat="server"/>
</form>
</body>
</html>