simplemain.aspx.cs

来自「csharp课本的源代码」· CS 代码 · 共 86 行

CS
86
字号
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void dropDownListProvince_SelectedIndexChanged(object sender, EventArgs e)
    {
        
        switch (dropDownListProvince.SelectedItem.Text)
        {
            case "河北省":
                listBoxCity.Items.Clear();
                listBoxCity.Items.Add("石家庄市");
                listBoxCity.Items.Add("秦皇岛市");
                
                break;
            case "山东省":
                listBoxCity.Items.Clear();
                listBoxCity.Items.Add("济南市");
                listBoxCity.Items.Add("青岛市");
                
                break;
            case "浙江省":
                listBoxCity.Items.Clear();
                listBoxCity.Items.Add("杭州市");
                listBoxCity.Items.Add("宁波市");
               
                break;
         
        }
        
    }
    protected void buttonOK_Click(object sender, EventArgs e)
    {
        string strname, strpassword, strsex, strwork, strlocation, strhobby = "";
        if (textBoxName.Text == "")
        {
            Response.Write("<script>window.alert('用户名不能为空!');</script>");
        }
        else
        {
            strname = textBoxName.Text;
            strpassword = textBoxPassword.Text;
            if (radioButtonMale.Checked)
            {
                strsex = "  男";
            }
            else
            {
                strsex = "  女";
            }
            strwork = radioButtonListWork.SelectedItem.Text;
            strlocation = dropDownListProvince.SelectedItem.Text + "、" + listBoxCity.SelectedItem.Text;
            for (int i = 0; i < checkBoxListHobby.Items.Count; i++)
            {
                if (checkBoxListHobby.Items[i].Selected)
                {
                    strhobby += checkBoxListHobby.Items[i].Text + "、";
                }
            }
            if (strhobby.EndsWith("、") == true)
            {
                strhobby = strhobby.Substring(0, strhobby.Length - 1);
            }

            Response.Redirect(string.Format(
               "SimpleResult.aspx?name={0}&sex={1}&work={2}&location={3}&hobby={4}",
               strname, strsex, strwork, strlocation, strhobby));
        }

    }
    
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?