1.在VS中添加dome5,将已经下好的easyui复制过来,添加引用Newtonsoft.Json.dll
2.创建HtmlPage1.html
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script src="easyui/jquery.min.js"></script>
<script src="easyui/jquery.easyui.min.js"></script>
<link href="easyui/themes/icon.css" rel="stylesheet" />
<link href="easyui/themes/default/easyui.css" rel="stylesheet" />
<script src="easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
$(function () {
var data = [{ id: 1, text: "夕颜" }, { id: 2, text: "暮颜",selected:true }, { id: 3, text: "朝颜" }]
$("#com").combobox({
editable: false,
//数据列表加载。
data: data,
valueField: 'id',
textField: 'text',
});
$("#com1").combobox({
editable: false,
//通过URL加载远程列表数据
url: 'WebProall.aspx',
valueField: 'ProvinceId',
textField: 'ProviceName',
onLoadSuccess: function () {
//获取下拉列表绑定的所有数据
var a = $("#com1").combobox("getData");
//选中默认第一个
$("#com1").combobox("select",a[0].ProvinceId)
},
onSelect: function () {
var value = $("#com1").combobox("getValue");
$("#com2").combobox(
{
url: 'WebCity.aspx?ProvinceId=' + value,
valueField: 'CityId',
textField: 'CityName',
onLoadSuccess: function () {
var a = $("#com2").combobox("getData");
$("#com2").combobox("select", a[0].CityId)
}
}
);
}
});
$("#com2").combobox({
editable: false
});
})
</script>
body里的代码
<input type="text" id="com" /><br />
省:<input type="text" id="com1" />
市:<input type="text" id="com2" />
3.添加ADO.NET实体数据模型(省略)
4.添加WebProall.aspx
aspx里面删掉多余代码,只剩下下面部分
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebProall.aspx.cs" Inherits="dome5.WebProall" %>
.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
namespace dome5
{
public partial class WebProall : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
using (CustomerSYSEntities db=new CustomerSYSEntities())
{
var pro = db.Province;
string str = JsonConvert.SerializeObject(pro);
Response.Write(str);
}
}
}
}
5.同上添加WebCity.aspx
.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
namespace dome5
{
public partial class WebCity : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
using (CustomerSYSEntities db=new CustomerSYSEntities())
{
//var city = db.City;
//string str = JsonConvert.SerializeObject(city);
//Response.Write(str);
int ProvinceId = int.Parse(Request["ProvinceId"]);
using (CustomerSYSEntities d=new CustomerSYSEntities())
{
var linq = from a in d.City
where a.ProviceId == ProvinceId
select a;
string str = JsonConvert.SerializeObject(linq);
Response.Write(str);
}
}
}
}
}