vs2015 dynamicweb4-2

webform1.aspx

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

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <center><h3>个人信息</h3></center>
        <table border="1">
            <tr>
                <td>性别:</td>
                <td>
                    <asp:RadioButton ID="rbMale" runat="server" Text="男" GroupName="sex" Checked="true" />
                    <asp:RadioButton ID="rbFemale" runat="server" Text="女" GroupName="sex" />
                </td>
            </tr>
            <tr>
                <td>
                    生源地:
                </td>
                <td>
                    <asp:RadioButtonList ID="rblOrigin" runat="server" RepeatDirection="Horizontal">
                        <asp:ListItem Selected="False" Value="0">兰州市</asp:ListItem>
                        <asp:ListItem Selected="False" Value="1">市外省内</asp:ListItem>
                        <asp:ListItem Selected="False" Value="2">甘肃省外</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:Button ID="btnSubmit" runat="server" Text="确定" OnClick="btnSubmit_Click" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:Label ID="lblTips" runat="server" Text=""></asp:Label>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

webform1.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace dynamicweb4_2
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (rbMale.Checked)
            {
                lblTips.Text = "性别:男<br>";
            }
            else
            {
                lblTips.Text = "性别:女<br>";
            }

            if (rblOrigin.SelectedIndex != -1)
            {
                lblTips.Text += "生源地:" + rblOrigin.SelectedItem.Text + "<br>";
            }
            else
            {
                lblTips.Text += "生源地:未经性选择";
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/modern358/article/details/115391652