■ RadioButtonList 클래스 사용하기

------------------------------------------------------------------------------------------------------------------------

MainPage.aspx

 

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MainPage.aspx.cs" Inherits="TestProject.MainPage" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <title>RadioButtonList 클래스 사용하기</title>

    </head>

    <body>

        <form id="form" runat="server">

        <div>

            <asp:RadioButtonList ID="radioButtonList" runat="server"

                RepeatDirection="Horizontal">

                <asp:ListItem Selected="True">남자</asp:ListItem>

                <asp:ListItem>여자</asp:ListItem>

            </asp:RadioButtonList>

            <asp:Button ID="printButton" runat="server"

                Text="출력"

                OnClick="printButton_Click" />

        </div>

        </form>

    </body>

</html>

 

 

MainPage.aspx.cs

 

 

using System;

using System.Web.UI;

 

namespace TestProject

{

    /// <summary>

    /// 메인 페이지

    /// </summary>

    public partial class MainPage : Page

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Protected

 

        #region 페이지 로드시 처리하기 - Page_Load(sender, e)

 

        /// <summary>

        /// 페이지 로드시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        protected void Page_Load(object sender, EventArgs e)

        {

        }

 

        #endregion

        #region 출력 버튼 클릭시 처리하기 - printButton_Click(sender, e)

 

        /// <summary>

        /// 출력 버튼 클릭시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        protected void printButton_Click(object sender, EventArgs e)

        {

            if(this.radioButtonList.SelectedItem.Text == "남자")

            {

                Response.Write("남자 <br />");

            }

            else

            {

                Response.Write("여자 <br />");

            }

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요