事件委托写法、三级联动

一、程序制作的步骤:
1、想想是要实现什么功能,把界面搭出来
2、想想在哪里写代码
3、补齐一些小问题

如果这3步也解决不了问题,那么问题出在你就不知道这个程序是要干什么

二、用户体验问题:
让用户简便的操作 - 站在使用者的角度来考虑程序的设计

去网上找一些类似的程序来看看他们是如何设计的,或者是模板

三、控件数据的加载:
例如:DropDownList里面添加年月日,不需要手动添加,可是使用循环

数据库数据加载:

四、事件的委托写法:
优点:清晰,易于查找

控件名.事件名 += (按两下tab键,会自动创建事件出来)

把光标放在事件,按F12可以快速到该事件的代码段去。

五、三级联动:
AutoPostBack - 自动提交事件

六、Repeater灵活使用:
不要认为Repeater只能制作table表格,它叫重复器,可以重复的制作任何东西

七、JS知识补充:
1、用JS来制作超链接按钮 - window.open();
2、如果要把JS代码写在head里面,那么需要加window.onload事件
注意:
JS的方法不能写在onload事件中

.aspx文件中的代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>
            <asp:Label ID="Label8" runat="server" Text="籍贯:"></asp:Label>
            <asp:DropDownList ID="DropDownList5" runat="server" Height="20" Width="70" AutoPostBack="True"></asp:DropDownList>
            <asp:DropDownList ID="DropDownList6" runat="server" Height="20" Width="70" AutoPostBack="True"></asp:DropDownList>
            <asp:DropDownList ID="DropDownList7" runat="server" Height="20" Width="70" AutoPostBack="True"></asp:DropDownList>
        </div>
    </form>
</body>
</html>

.aspx.cs文件中的代码

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

public partial class _Default : System.Web.UI.Page
{
    List<login> list = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        DropDownList5.SelectedIndexChanged += DropDownList5_SelectedIndexChanged;//省改变市自动变
        DropDownList6.SelectedIndexChanged += DropDownList6_SelectedIndexChanged;//市改变区自动变
        if (IsPostBack == false)
        {
            list = new date().selectChina("0001");//添加省
            DropDownList5.DataSource = list;
            DropDownList5.DataTextField = "AreaName";
            DropDownList5.DataValueField = "AreaCode";
            DropDownList5.DataBind();
            list = new date().selectChina(DropDownList5.SelectedItem.Value);//添加市
            DropDownList6.DataSource = list;
            DropDownList6.DataTextField = "AreaName";
            DropDownList6.DataValueField = "AreaCode";
            DropDownList6.DataBind();
            list = new date().selectChina(DropDownList6.SelectedItem.Value);//添加区
            DropDownList7.DataSource = list;
            DropDownList7.DataTextField = "AreaName";
            DropDownList7.DataValueField = "AreaCode";
            DropDownList7.DataBind();
        }
    }

    void DropDownList6_SelectedIndexChanged(object sender, EventArgs e)
    {
        list = new date().selectChina(DropDownList6.SelectedItem.Value);
        DropDownList7.DataSource = list;
        DropDownList7.DataTextField = "AreaName";
        DropDownList7.DataValueField = "AreaCode";
        DropDownList7.DataBind();
    }

    void DropDownList5_SelectedIndexChanged(object sender, EventArgs e)
    {
        list = new date().selectChina(DropDownList5.SelectedItem.Value);//添加市
        DropDownList6.DataSource = list;
        DropDownList6.DataTextField = "AreaName";
        DropDownList6.DataValueField = "AreaCode";
        DropDownList6.DataBind();
        list = new date().selectChina(DropDownList6.SelectedItem.Value);//添加区
        DropDownList7.DataSource = list;
        DropDownList7.DataTextField = "AreaName";
        DropDownList7.DataValueField = "AreaCode";
        DropDownList7.DataBind();
    }

}
原文地址:https://www.cnblogs.com/123lucy/p/5679394.html