liandong.aspx:
------------------------------------------
為內(nèi)丘等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及內(nèi)丘網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站設(shè)計、網(wǎng)站制作、內(nèi)丘網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="liandong.aspx.cs" Inherits="WebApplication1.liandong" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>無標(biāo)題頁</title> <script src="script/jquery-1.6.2.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> $(function() { $("#DropDownList1").change(function() { var defaultValue = "<option value='-1'>--請選擇--</option>"; $("#DropDownList2").html(defaultValue); $("#DropDownList3").html(defaultValue); showMsg("#DropDownList1", "#DropDownList2"); }) $("#DropDownList2").change(function() { var defaultValue = "<option value='-1'>--請選擇--</option>"; $("#DropDownList3").html(defaultValue); showMsg("#DropDownList2", "#DropDownList3"); }) }) function showMsg(sender, receiver) { var d1 = $(sender).val(); $.ajax({ type: 'get', dataType: "json", url: 'liandong.ashx', data: 'pid=' + d1, success: function(data) { $.each(data, function(i, o) { var opts = "<option value='" + o.id + "'>" + o.name + "</option>"; $(receiver).append(opts); }) } }) } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem Value="-1">--請選擇--</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server"> <asp:ListItem Value="-1">--請選擇--</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="DropDownList3" runat="server"> <asp:ListItem Value="-1">--請選擇--</asp:ListItem> </asp:DropDownList> </div> </form> </body> </html>
liandong.aspx.cs
-------------------------------------------------------------------------------------------
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; namespace WebApplication1 { public partial class liandong : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { string sql = "select * from t_ld where pid=0"; DataTable dt = DBhelper.query(sql); foreach (DataRow dr in dt.Rows) { ListItem li = new ListItem(dr["name"].ToString(), dr["id"].ToString()); this.DropDownList1.Items.Add(li); } } } } }
liandong.ashx.cs
using System; using System.Collections; using System.Data; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml.Linq; namespace WebApplication1 { /// <summary> /// $codebehindclassname$ 的摘要說明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class liandong1 : IHttpHandler { public void Proce***equest(HttpContext context) { context.Response.ContentType = "text/html"; if(!string.IsNullOrEmpty(context.Request.QueryString["pid"])) { int pid = Convert.ToInt32(context.Request.QueryString["pid"]); string sql = "select * from t_ld where pid=" + pid; DataTable dt = DBhelper.query(sql); string json_str = ""; json_str += "["; foreach (DataRow dr in dt.Rows) { json_str += "{\"id\""; json_str += ":"; json_str += "\"" + dr["id"].ToString() + "\""; json_str += ","; json_str += "\"name\""; json_str += ":"; json_str += "\"" + dr["name"].ToString() + "\""; json_str += "}"; json_str += ","; } json_str = json_str.Substring(0, json_str.Length - 1); json_str += "]"; context.Response.Write(json_str); } } public bool IsReusable { get { return false; } } } }
網(wǎng)頁標(biāo)題:asp.net三級聯(lián)動(jquery+json)
文章地址:http://chinadenli.net/article40/gpcoeo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計公司、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)