62,046
社区成员
发帖
与我相关
我的任务
分享
<td>
<%=new WebUI.Append.Append().ToString()%>
</td>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class GetProvince : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
string id = context.Request.QueryString["id"];
if (id == null) return;
List<Model.Province> provinces = new BLL.Province().GetList("", "AreaID='" + id + "'", "");
context.Response.Write("<option value='0'>选择省份</option>");
foreach (Model.Province province in provinces)
{
context.Response.Write("<option value='" + province.ProvinceID + "'>");
context.Response.Write(province.ProvinceName);
context.Response.Write("</option>");
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WebUI.Append
{
public class Append
{
public override string ToString()
{
StringBuilder html = new StringBuilder();
#region --省市区联动
html.Append("<script type='text/javascript'>");
html.Append("function getprovince(id)\n");
html.Append("{\n");
html.Append("$(\".province\").html(\"<option>加载中...</option>\");\n");
html.Append("$(\".city\").html(\"<option value='0'>选择城市</option>\");\n");
html.Append("$.ajax({\n");
html.Append("type:\"get\",\n");
html.Append("url:\"/page/Base/ajax/GetProvince.ashx\",\n");
html.Append("data:encodeURI(\"id=\"+id),\n");
html.Append("dataType:\"html\",\n");
html.Append("success:function(data){\n");
html.Append("$(\".province\").html(data);\n");
html.Append("},\n");
html.Append("error:function(data){\n");
html.Append("alert(data);\n");
html.Append("}\n");
html.Append("});\n");
html.Append("}\n");
html.Append("\n");
html.Append("function getCity(id)\n");
html.Append("{\n");
html.Append("//清空城市和区县列表\n");
html.Append("$(\".city\").html(\"<option>加载中...</option>\");\n");
html.Append("$(\".district\").html(\"<option value='0'>选择区县</option>\");\n");
html.Append("$.ajax({\n");
html.Append("type:\"get\",\n");
html.Append("url:\"/page/Base/ajax/Getcity.ashx\",\n");
html.Append("data:\"id=\"+id,\n");
html.Append("dataType:\"html\",\n");
html.Append("success:function(data){\n");
html.Append("$(\".city\").html(data);\n");
html.Append("},\n");
html.Append("error:function(data){\n");
html.Append("alert(data);\n");
html.Append("}\n");
html.Append("});\n");
html.Append("}\n");
html.Append("\n");
html.Append("function getDistrict(id)\n");
html.Append("{\n");
html.Append("$(\".district\").html(\"<option>加载中...</option>\");\n");
html.Append("$.ajax({\n");
html.Append("type:\"get\",\n");
html.Append("url:\"/page/Base/ajax/GetDistrict.ashx\",\n");
html.Append("data:\"id=\"+id,\n");
html.Append("dataType:\"html\",\n");
html.Append("success:function(data){\n");
html.Append("$(\".district\").html(data);\n");
html.Append("},\n");
html.Append("error:function(data){\n");
html.Append("alert(data);\n");
html.Append("}\n");
html.Append("});\n");
html.Append("}\n");
html.Append("</script>");
html.Append("<table style='width:150px;'>");
List<Model.Area> areas = new BLL.Area().GetAllList();
html.Append("<tr>");
html.Append("<td>");
//html.Append("大区");
html.Append("<select name='area' class='area' onchange='getprovince($(this).val())'>");
html.Append("<option value='0'>选择大区</option >");
foreach (Model.Area row in areas)
{
html.Append("<option value='" + row.AreaID + "'>" + row.AreaName + "</option>");
}
html.Append("</select>");
html.Append("</td>");
html.Append("<td>");
html.Append("<select name='province' class='province' onchange='getCity($(this).val())'>");
html.Append("<option value='0'>选择省份</option >");
html.Append("</select>");
html.Append("</td>");
html.Append("<td>");
//html.Append("城市");
html.Append("<select name='city' class='city' onchange='getDistrict($(this).val())'>");
html.Append("<option value='0'>选择城市</option>");
html.Append("</select>");
html.Append("</td>");
html.Append("<td>");
//html.Append("区县");
html.Append("<select name='district' class='district'>");
html.Append("<option value='0'>选择区县</option>");
html.Append("</select>");
html.Append("</td>");
html.Append("</tr>");
html.Append("</table>");
return html.ToString();
#endregion
}
}
}
<asp:DropDownList ID="ddlChild" runat="server" Width="15%" AutoPostBack="True" OnSelectedIndexChanged="ddlChild_SelectedIndexChanged">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
//代码
</ContentTemplate>
</asp:UpdatePanel>
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Collections.Generic;
using System.Collections.Specialized;
using DataAccess;
using AjaxControlToolkit;
using BLL;
/// <summary>
/// GetDLDetailInfo 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class GetDLDetailInfo : System.Web.Services.WebService
{
private DataTable _myTable;
private province _myProvinceOper = new province();
private List<CascadingDropDownNameValue> _values;
public GetDLDetailInfo()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public CascadingDropDownNameValue[] GetProvince(string knownCategoryValues, string category)
{
_myTable = _myProvinceOper.SelectAllProvince();
_values = new List<CascadingDropDownNameValue>();
foreach (DataRow _r in _myTable.Rows)
{
_values.Add(new CascadingDropDownNameValue(_r["province"].ToString(), _r["provinceID"].ToString()));
}
return _values.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] GetCityByProvince(string knownCategoryValues, string category)
{
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
int _provinceID;
if (!kv.ContainsKey("province") || !Int32.TryParse(kv["province"], out _provinceID))
{
return null;
}
_myTable = _myProvinceOper.SelectAllCity(_provinceID);
_values = new List<CascadingDropDownNameValue>();
foreach (DataRow _r in _myTable.Rows)
{
_values.Add(new CascadingDropDownNameValue(_r["city"].ToString(), _r["cityID"].ToString()));
}
return _values.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] GetAreaByCity(string knownCategoryValues, string category)
{
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
int _cityID;
if (!kv.ContainsKey("city") || !Int32.TryParse(kv["city"], out _cityID))
{
return null;
}
_myTable = _myProvinceOper.SelectAllArea(_cityID);
_values = new List<CascadingDropDownNameValue>();
foreach (DataRow _r in _myTable.Rows)
{
_values.Add(new CascadingDropDownNameValue(_r["area"].ToString(), _r["areaID"].ToString()));
}
return _values.ToArray();
}
}