zoukankan      html  css  js  c++  java
  • webform 联动查询代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Drawing;
    
    
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)//获取一个值,该值指示页面是第一次呈现还是为了相应回发而加载
            {
                Dropdownlist();
            }
        }
    
    
        //第一种显示方法
        public void Dropdownlist()
        {
            List<ChinaStates> list = new ChinaBF().SelectByParent("0001");
            foreach (ChinaStates data in list)
            {
                ListItem it = new ListItem(data.AreaName,data.AreaCode);
                DropDownList1.Items.Add(it);
            }  
        }
    //第二种显示方法
        public void BindDropdownlist()
        {
            List<ChinaStates> list = new ChinaBF().SelectByParent("0001");
            DropDownList1.DataSource = list;
            DropDownList1.DataTextField = "AreaName";
            DropDownList1.DataValueField = "AreaCode";
            DropDownList1.DataBind();
        }
    
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Label1.Text = DropDownList1.SelectedItem.Text;
            string a = DropDownList1.SelectedItem.Value;
            List<ChinaStates> list = new ChinaBF().SelectByParent(a);
            DropDownList2.DataSource = list;
            DropDownList2.DataTextField = "AreaName";
            DropDownList2.DataValueField = "AreaCode";
            DropDownList2.DataBind();
    
            string b = DropDownList2.SelectedItem.Value;
            List<ChinaStates> list1 = new ChinaBF().SelectByParent(b);
            DropDownList3.DataSource = list1;
            DropDownList3.DataTextField = "AreaName";
            DropDownList3.DataValueField = "AreaCode";
            DropDownList3.DataBind();
        }
    
    
        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
             string b = DropDownList2.SelectedItem.Value;
            List<ChinaStates> list1 = new ChinaBF().SelectByParent(b);
            DropDownList3.DataSource = list1;
            DropDownList3.DataTextField = "AreaName";
            DropDownList3.DataValueField = "AreaCode";
            DropDownList3.DataBind();
        }
        //当点击注册的时候,判断验证码格式输入是否正确
    
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text.ToUpper().Trim() == Session["ValidateCode"].ToString().ToUpper().Trim())
            {
                Response.Write("<script>alert('登陆成功')</script>");
              
            }
            else
            {
                Response.Write("<script>alert('验证码格式不正确')</script>");
            }
        }
    }

    方法里的代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    /// <summary>
    /// ChinaBF 的摘要说明
    /// </summary>
    public class ChinaBF
    {
    
        private DataClassesDataContext _Context;
        public ChinaBF()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
    
       _Context=new DataClassesDataContext ();
            
        }
    
        public List<ChinaStates> Select()
        {
            return _Context.ChinaStates.ToList();
        }
    
        public List<ChinaStates> SelectByParent(string id)
        {
            return _Context.ChinaStates.Where(p=>p.ParentAreaCode==id) .ToList();
        }
    }


    Html里的源代码

    <%@ 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>
        
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <br />
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <br />
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
                <ContentTemplate>
                    &nbsp;&nbsp; 家庭住址:省份: 
                    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                    </asp:DropDownList>
                    &nbsp;市:<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
                    </asp:DropDownList>
                    &nbsp; 区<asp:DropDownList ID="DropDownList3" runat="server">
                    </asp:DropDownList>
    <br />
                </ContentTemplate>
            </asp:UpdatePanel>
            <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <br />
            <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 请输入验证码:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    &nbsp;&nbsp;&nbsp; 验证码:<asp:Image ID="CreateImage" runat="server" />
            <br />
            <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="注册" />
    
           
          
        
        </div>
        </form>
    </body>
    </html>
  • 相关阅读:
    设置lable内容不上下居中
    iOS中webView加载URL需要处理特殊字符
    搞一个app需要多久?
    戏说HTML5
    限制UITextField/UITextView的输入字数与中文输入之后的英文换行问题
    iOS6以后的单个控制器横竖屏显示以及旋转屏控制技巧,附带iOS8以后显示电池状态栏
    纯命令行教你Cocoapods的安装和使用
    iOS开发之各种动画各种页面切面效果
    UITextView/UITextField检测并过滤Emoji表情符号
    类里面的大括号{}加载顺序
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4658819.html
Copyright © 2011-2022 走看看