제목 : 동적으로 생성된 라디오 버튼의 값을 C#에서 받아오기
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FrmMultipleRadioButton.aspx.cs"
Inherits="MultipleRadioButton_FrmMultipleRadioButton" %>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
1번
<asp:RadioButtonList ID="rdo1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="A">A</asp:ListItem>
<asp:ListItem Value="B">B</asp:ListItem>
<asp:ListItem Value="C">C</asp:ListItem>
<asp:ListItem Value="D">D</asp:ListItem>
</asp:RadioButtonList>
2번
<asp:RadioButtonList ID="rdo2" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="A">A</asp:ListItem>
<asp:ListItem Value="B">B</asp:ListItem>
<asp:ListItem Value="C">C</asp:ListItem>
<asp:ListItem Value="D">D</asp:ListItem>
</asp:RadioButtonList>
<asp:Button ID="btnSelect" runat="server" Text="선택" onclick="btnSelect_Click" />
<asp:Label ID="lblDisplay" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
using System;
public partial class MultipleRadioButton_FrmMultipleRadioButton : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSelect_Click(object sender, EventArgs e)
{
string[] arr = new string[2];
for (int i = 0; i < 2; i++)
{
arr[i] = Request.Form["rdo" + (i + 1).ToString()];
}
string results = "<br />선택한 값 : <br />";
for (int i = 0; i < 2; i++)
{
results += arr[i] + "<br />";
}
this.lblDisplay.Text = results;
}
}