62,268
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxProTest.aspx.cs" Inherits="AjaxProTest" %>
<!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>AjaxPro测试</title>
<script type="text/javascript" language="javascript">
function GetPoliceList(id)
{
var result = AjaxProTest.GetPoliceSet(id);
var DropDownList = document.getElementById('DropSecond');
DropDownList.length = 0;
for(var i=0;i<result.length;i++)
{
DropDownList.options.add(new Option(result.Rows[i].note,result.Rows[i].code));
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropFirst" runat="server" onchange="GetPoliceList(document.getElementById('DropFirst').value)">
</asp:DropDownList>
<asp:DropDownList ID="DropSecond" runat="server">
</asp:DropDownList>
</div>
</form>
</body>
</html>
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;
public partial class AjaxProTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxProTest));//注册Ajax可调用的类的名称
if (!IsPostBack)
{
string sql = "SELECT CODE,NOTE FROM SM_AREA";
DataSet Area_Set = SqlExec.ExecuteDataset(sql);
DropFirst.DataSource = Area_Set.Tables[0].DefaultView;
DropFirst.DataValueField = "CODE";
DropFirst.DataTextField = "NOTE";
DropFirst.DataBind();
DropFirst.Items.Insert(0,new ListItem("---请选择---", ""));
string sql1 = "SELECT CODE,NOTE FROM SM_POLICE";
DataSet Police_Set = SqlExec.ExecuteDataset(sql1);
DropSecond.DataSource = Police_Set.Tables[0].DefaultView;
DropSecond.DataValueField = "CODE";
DropSecond.DataTextField = "NOTE";
DropSecond.DataBind();
DropSecond.Items.Insert(0, new ListItem("---请选择---", ""));
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}
[AjaxPro.AjaxMethod]
public DataTable GetPoliceSet(string AREACODE)
{
try
{
string sql = "SELECT CODE,NOTE,AREACODE FROM SM_POLICE WHERE AREACODE = '" + AREACODE + "'";
DataSet dataset = SqlExec.ExecuteDataset(sql);
return dataset.Tables[0];
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
return null;
}
}
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
</httpHandlers>
var result = AjaxProTest.GetPoliceSet(id).value;