asp.net三级联动(jquery+json)-创新互联

liandong.aspx:
------------------------------------------

成都创新互联公司于2013年成立,先为双塔等服务建站,双塔等地企业,进行企业商务咨询服务。为双塔企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="liandong.aspx.cs" Inherits="WebApplication1.liandong" %>





    无标题页

    
        
            $(function() {
                $("#DropDownList1").change(function() {
                    var defaultValue = "--请选择--";
                    $("#DropDownList2").html(defaultValue);
                    $("#DropDownList3").html(defaultValue);
                    showMsg("#DropDownList1", "#DropDownList2");
                })

                $("#DropDownList2").change(function() {
                    var defaultValue = "--请选择--";
                    $("#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 = "" + o.name + "";
                            $(receiver).append(opts);
                        })
                    }
                })
            }
    


    
    
                          --请选择--                               --请选择--                               --请选择--                   
    

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
{
    /// 
    /// $codebehindclassname$ 的摘要说明
    /// 
    [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;
            }
        }
    }
}

创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。


新闻名称:asp.net三级联动(jquery+json)-创新互联
文章路径:http://pwwzsj.com/article/cdjoos.html