첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ 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>ASP.NET 표준 컨트롤 사용하기</title>
    </head>
    <body>
        <form id="form" runat="server">
            <div>
                <table style="width: 500px">
                    <tr>
                        <td style="width:60px">이용 약관</td>
                        <td style="width:100px">
                            <asp:CheckBox ID="agreeCheckBox" runat="server"
                                Width="122px"
                                Checked="true"
                                Text="동의합니다." />
                        </td>
                    </tr>
                    <tr>
                        <td style="width:60px">취미</td>
                        <td style="width:100px">
                            <asp:CheckBoxList ID="hobbyCheckBoxList" runat="server"
                                Width="202px"
                                RepeatLayout="Flow"
                                RepeatDirection="Horizontal"
                                RepeatColumns="2">
                                <asp:ListItem Selected="True" Value="S">축구</asp:ListItem>
                                <asp:ListItem Value="V">배구</asp:ListItem>
                                <asp:ListItem Selected="True" Value="B">농구</asp:ListItem>
                            </asp:CheckBoxList>
                        </td>
                    </tr>
                    <tr>
                        <td style="width:60px">성별</td>
                        <td style="width:100px">
                            <asp:RadioButton ID="manRadioButton" runat="server"
                                GroupName="Gender"
                                Checked="true"
                                Text="남자" />
                            <asp:RadioButton ID="womanRadioButton" runat="server"
                                GroupName="Gender"
                                Text="여자" />
                        </td>
                    </tr>
                    <tr>
                        <td style="width:60px">결혼 여부</td>
                        <td style="width:100px">
                            <asp:RadioButtonList ID="weddingRadioButtonList" runat="server"
                                Width="110px"
                                RepeatLayout="Flow"
                                RepeatDirection="horizontal">
                                <asp:ListItem Selected="True">미혼</asp:ListItem>
                                <asp:ListItem>기혼</asp:ListItem>
                            </asp:RadioButtonList>
                        </td>
                    </tr>
                    <tr>
                        <td style="width:60px;height:24px">직업</td>
                        <td style="width:100px;height:24px">
                            <asp:DropDownList ID="jobDropDownList" runat="server">
                                <asp:ListItem>회사원</asp:ListItem>
                                <asp:ListItem Selected="True">공무원</asp:ListItem>
                                <asp:ListItem>백수</asp:ListItem>
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td style="width:60px">특기</td>
                        <td style="width:100px">
                            <asp:ListBox ID="favoriteListBox" runat="server"
                                SelectionMode="Multiple">
                            </asp:ListBox>
                        </td>
                    </tr>
                </table>
                <br />
                <asp:Button ID="okButton" runat="server"
                    Text="확인"
                    OnClick="okButton_Click" /><br />
                <br />
                <asp:Label ID="displayLabel" runat="server" />
            </div>
        </form>
    </body>
</html>

 

728x90

 

▶ MainPage.aspx.cs

using System;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TestProject
{
    /// <summary>
    /// 메인 페이지
    /// </summary>
    public partial class MainPage : Page
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Protected
        //////////////////////////////////////////////////////////////////////////////// Event

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

        /// <summary>
        /// 페이지 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
            {
                SetFavoriteListBoxData();
            }
        }

        #endregion
        #region 확인 버튼 클릭시 처리하기 - okButton_Click(sender, e)

        /// <summary>
        /// 확인 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        protected void okButton_Click(object sender, EventArgs e)
        {
            StringBuilder stringBuilder = new StringBuilder();

            if(this.agreeCheckBox.Checked)
            {
                stringBuilder.Append("[1] " + this.agreeCheckBox.Text + "<br />");
            }

            if(this.hobbyCheckBoxList.Items[0].Selected)
            {
                stringBuilder.Append("[2] " + this.hobbyCheckBoxList.Items[0].Value + "<br />");
            }

            if(this.hobbyCheckBoxList.Items[1].Selected)
            {
                stringBuilder.AppendFormat("[2] {0}<br/>", this.hobbyCheckBoxList.Items[1].Value);
            }

            if(this.hobbyCheckBoxList.Items[2].Selected)
            {
                stringBuilder.AppendFormat("[2] {0}<br/>", this.hobbyCheckBoxList.Items[2].Value);
            }

            if(this.manRadioButton.Checked)
            {
                stringBuilder.AppendFormat("[3] {0} 선택<br />", this.manRadioButton.Text);
            }
            else
            {
                stringBuilder.AppendFormat("[3] {0} 선택<br />", this.womanRadioButton.Text);
            }

            stringBuilder.AppendFormat("[4] {0}<br />", this.weddingRadioButtonList.SelectedItem.Text);

            stringBuilder.AppendFormat("[5] {0}<br />",

            this.jobDropDownList.Items[this.jobDropDownList.SelectedIndex].Value);

            for(int i = 0; i < this.favoriteListBox.Items.Count; i++)
            {
                if(this.favoriteListBox.Items[i].Selected)
                {
                    stringBuilder.AppendFormat("[6] {0}<br />", this.favoriteListBox.Items[i].Value);
                }
            }

            foreach(ListItem listItem in this.favoriteListBox.Items)
            {
                if (listItem.Selected)
                {
                    stringBuilder.AppendFormat("[6] {0}<br />", listItem.Text);
                }
            }

            this.displayLabel.Text = stringBuilder.ToString();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 특기 리스트 박스 데이터 설정하기 - SetFavoriteListBoxData()

        /// <summary>
        /// 특기 리스트 박스 데이터 설정하기
        /// </summary>
        private void SetFavoriteListBoxData()
        {
            this.favoriteListBox.Items.Add("C#");
            this.favoriteListBox.Items.Add("ASP.NET");

            ListItem listItem = new ListItem();

            listItem.Text  = "자바스크립트";
            listItem.Value = "JavaScript";

            this.favoriteListBox.Items.Add(listItem);

            listItem = new ListItem("닷넷", ".NET");

            this.favoriteListBox.Items.Add(listItem);
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요