<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" EnableEventValidation="false" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="club_Default" Title="无标题页" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript">
$(document).ready(function() {
//预先加载第一个select,加载省,看好加载的的页面Handlerprovince.ashx
$.post('Handlerprovince.ashx', {}, function(data) { $("#ctl00_ContentPlaceHolder1_ddl_province").html(data) }, 'html');
//当选择省的时候加载二级市,构成联动
$("#ctl00_ContentPlaceHolder1_ddl_province").change(function() {
$.post('Handlercity.ashx', { cartype: $(this).val() }, function(data) { $("#ctl00_ContentPlaceHolder1_ddl_city").empty().html(data) }, 'html');
});
//当选择二级市的时候加载区县,构成联动
$("#ctl00_ContentPlaceHolder1_ddl_city").change(function() {
$.post('Handlerarea.ashx', { cartype: $(this).val() }, function(data) { $("#ctl00_ContentPlaceHolder1_ddl_area").empty().html(data) }, 'html');
});
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:DropDownList ID="ddl_province" runat="server">
</asp:DropDownList>
省
<asp:DropDownList ID="ddl_city" runat="server">
</asp:DropDownList>市
<asp:DropDownList ID="ddl_area" runat="server">
</asp:DropDownList>区/县<br />
<asp:Button ID="Button1" runat="server" Text="Button"
οnclick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</asp:Content>
protected void Button1_Click(object sender, EventArgs e)
{
this.Label1.Text = Request.Form[ddl_province.UniqueID].ToString();
}
这里取出来得是value值
using System;
using System.Web;
using System.Data;
using System.Text;
public class Handlerprovince : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Clear();
DataTable dt = new DataTable();
string sql = "select * from province order by name";
SQLHelper.FillDataTable(sql, dt);
StringBuilder st = new StringBuilder();
st.Append("<option value=\"\">--请选择--</option>");
foreach (DataRow item in dt.Rows)
{
st.Append("<option value=\"" + item["code"] + "\">" + item["name"] + "</option>");
}
context.Response.Write(st.ToString());
}
public bool IsReusable {
get {
return false;
}
}
}
using System;
using System.Web;
using System.Data;
using System.Text;
public class Handlercity : IHttpHandler
{
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Clear();
string provinceId = context.Request.Form[0].ToString();
DataTable dt = new DataTable();
string sql = "select * from city where provinceId='" + provinceId + "' order by name";
SQLHelper.FillDataTable(sql, dt);
StringBuilder st = new StringBuilder();
st.Append("<option value=\"\">--请选择--</option>");
foreach (DataRow item in dt.Rows)
{
st.Append("<option value=\"" + item["code"] + "\">" + item["name"] + "</option>");
}
context.Response.Write(st.ToString());
}
public bool IsReusable {
get {
return false;
}
}
}
using System;
using System.Web;
using System.Data;
using System.Text;
public class Handlerarea : IHttpHandler
{
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Clear();
string cityid = context.Request.Form[0].ToString();
DataTable dt = new DataTable();
string sql = "select * from [area] where [cityId]='" + cityid + "' order by name";
SQLHelper.FillDataTable(sql, dt);
StringBuilder st = new StringBuilder();
st.Append("<option value=\"\">--请选择--</option>");
foreach (DataRow item in dt.Rows)
{
st.Append("<option value=\"" + item["code"] + "\">" + item["name"] + "</option>");
}
context.Response.Write(st.ToString());
}
public bool IsReusable {
get {
return false;
}
}
}