码迷,mamicode.com
首页 > Web开发 > 详细

webform 联动查询代码

时间:2015-07-19 17:41:29      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

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>

 

webform 联动查询代码

标签:

原文地址:http://www.cnblogs.com/275147378abc/p/4658819.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!