AJAX无刷新实现三级联动并获取DropDownList的值的方法

前台 要显示的(级联的页面) 
以上是前台要显示的页面,如果要接受值的  只要页面最下面的 隐藏域的值即可,相信你会在后台页面获取前台的值 实在不行你就把吟唱与换成Lable
  1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AdvancedSearch.aspx.cs"
  2     Inherits="SchoolCrm.Web.AdvancedSearch" MasterPageFile="~/FrontDeskShow.Master"
  3     EnableEventValidation="false" %>
  4 
  5 <%@ Register Assembly="SchoolCrm.Web" Namespace="SchoolCrm.Web.Contorls" TagPrefix="cc1" %>
  6 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
  7     <style type="text/css">
  8         #tablestyle
  9         {
 10             width: 100%;
 11             border-style: solid;
 12         }
 13         #tdTitle
 14         {
 15             text-align: center;
 16             background-color: #F0F7F9;
 17         }
 18         #tabletd
 19         {
 20             background-color: White;
 21             border-bottom-width: 2px;
 22         }
 23         #ProfessionName
 24         {
 25             width: 134px;
 26         }
 27     </style>
 28 
 29     <script type="text/javascript">
 30   
 31         //省市级联 --省份
 32         $(function() {
 33 
 34             $("#ctl00_Content_DropProvinceList1").focus(function() {
 35                 var text_val = $(this).val();
 36                 if (text_val == this.defaultValue) {
 37                     $(this).val("");
 38                 }
 39             }).blur(function() {
 40                 var text_val = $(this).val();
 41                 if (text_val == "") {
 42                     $(this).val(this.defaultValue);
 43                 } else {
 44                     var name = $(this).val();
 45 
 46                     $.post("AjaxToprofessionaByWhere.aspx", { ProvinceNameId: encodeURI(name) }, function(data, success) {
 47                         if (success == "success") {
 48                             $("#ctl00_Content_DropCityList1").html(data);
 49                         }
 50                     });
 51                 }
 52             });
 53         })
 54 
 55 
 56         function getData() {
 57           
 58             $("#ctl00_Content_SchoolHidden").val(str1);
 59             //城市
 60             var str1 = $("#ctl00_Content_DropCityList1 :selected").val();
 61             $("#ctl00_Content_CityHidden").val(str1);
 62           
 63         }
 64 
 65     </script>
 66 
 67 </asp:Content>
 68 <asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="server">
 69     <div>
 70         <table id="tablestyle" border="0" cellpadding="5" cellspacing="1" bgcolor="#B5D6E7">
 71             <tr>
 72                 <td id="tdTitle">
 73                     所属地
 74                 </td>
 75                 <td id="tabletd">
 76                     <asp:DropDownList ID="DropCountryList1" runat="server" Height="23px" Width="100px"
 77                         Enabled="False">
 78                     </asp:DropDownList>
 79                     <cc1:DropProvinceList ID="DropProvinceList1" runat="server" Height="23px" Width="100px">
 80                         <asp:ListItem Value="0">请选择</asp:ListItem>
 81                     </cc1:DropProvinceList>
 82                     <cc1:DropCityList ID="DropCityList1" runat="server" Height="23px" Width="100px">
 83                         <asp:ListItem Value="0">请选择</asp:ListItem>
 84                     </cc1:DropCityList>
 85                 </td>
 86             </tr>
 87             <tr>
 88                 <td id="tdTitle">
 89                 </td>
 90                 <td id="tabletd">
 91                     <asp:Button ID="Search" runat="server" Text="搜索" OnClick="Search_Click" OnClientClick="return getData()" />
 92                     &nbsp;&nbsp;&nbsp;
 93                     <asp:Button ID="btnCancel" runat="server" Text="取消" OnClick="btnCancel_Click" />
 94                 </td>
 95             </tr>
 96         </table>
 97     </div>
 98     <input type="hidden" id="profeeHidden" runat="server" />
 99     <input type="hidden" id="SchoolHidden" runat="server" />
100     <input type="hidden" id="CityHidden" runat="server" />
101     <input type="hidden" id="DergeeHidden" runat="server" />
102 </asp:Content>
接受的页面,这个页面只是一个单独的页面只是接收值,传值使用
------以上代码供大家 参考,如果不明白的,请留言,我会帮大家一一解决的!
 1 using System;
 2 using System.Collections;
 3 using System.Configuration;
 4 using System.Data;
 5 using System.Linq;
 6 using System.Web;
 7 using System.Web.Security;
 8 using System.Web.UI;
 9 using System.Web.UI.HtmlControls;
10 using System.Web.UI.WebControls;
11 using System.Web.UI.WebControls.WebParts;
12 using System.Xml.Linq;
13 using System.Collections.Generic;
14 using System.Text;
15 using System.Web.Script.Serialization;
16 
17 
18 namespace SchoolCrm.Web
19 {
20     public partial class AjaxToprofessionaByWhere : System.Web.UI.Page
21     {
22         protected void Page_Load(object sender, EventArgs e)
23         {
24             if (!IsPostBack)
25             {
26                 if (Request["ProvinceNameId"] != null)
27                 {
28                     ProvinceName(Request["ProvinceNameId"].ToString());
29                 }
30             }
31         }
32 
33         BLL.Country country = new SchoolCrm.BLL.Country();
34         BLL.Province province = new SchoolCrm.BLL.Province();
35         BLL.City city = new SchoolCrm.BLL.City();
36 
37         /// <summary>
38         /// 省市级联  --省份
39         /// </summary>
40         /// <param name="ProfessionalName"></param>
41         private void ProvinceName(string ProvinceNameId)
42         {
43             string url = Server.UrlDecode(ProvinceNameId);
44             List<Model.City> list = city.SelectCityByProvinceIdAndCountryId("1", url);
45             // List<Model.Province> list = province.SelectProvinceByCountryId(url);
46             StringBuilder str = new StringBuilder();
47             str.AppendFormat("<option value='{0}'>{1}</option>", 0, "请选择");
48             foreach (Model.City item in list)
49             {
50                 str.AppendFormat("<option value='{0}'>{1}</option>", item.CityId, item.ChineseName);
51             }
52             Response.Write(str.ToString());
53             Response.End();
54 
55 
56 
57         }
58 
59     }
60 }
posted @ 2012-06-28 11:23  程序猿网友666  阅读(334)  评论(0编辑  收藏  举报