<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ajaxtest.aspx.cs" Inherits="ajaxtest" %>
<!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-DropDownList无刷新联动</title>
<script language="javascript" type="text/javascript">
function GetTeamList()
{
var System=document.getElementById("SystemList");
ajaxtest.TeamName(System.value,TeamCallBack);}
function TeamCallBack(response)
{
if(response.value !=null)
{
var team=document.getElementById("TeamList");
var dt=response.value;
team.length=0;
for(var i=0;i<dt.Rows.length;i++)
{
var team_text=dt.Rows[i]["name"];
var team_value=dt.Rows[i]["name"];
team.options.add(new Option(team_text,team_value));
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="SystemList" runat="server" Width="120px">
</asp:DropDownList>
<asp:DropDownList ID="TeamList" runat="server" Width="120px">
</asp:DropDownList></div>
</form>
</body>
</html>
后台:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class ajaxtest : System.Web.UI.Page
{
pub b = new pub();
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(ajaxtest)); if (!Page.IsPostBack)
{
SystemName();
TeamList.DataSource = TeamName(SystemList.SelectedValue.Trim());
TeamList.DataTextField = "mc";
TeamList.DataValueField = "mc";
TeamList.DataBind();
SystemList.Attributes.Add("onchange", "GetTeamList();");
}
}
private void SystemName()
{
try
{
DataSet ds = b.GetDataSet("select mc from city where lx=1", "cspq");
SystemList.DataSource =ds.Tables[0];
SystemList.DataTextField = "mc";
SystemList.DataValueField = "mc";
SystemList.DataBind();
}
catch
{ }
} [AjaxPro.AjaxMethod]
/**//// <summary>
/// ajax调用方法
/// </summary>
/// <param name="systemselectname"></param>
public DataTable TeamName(string systemselectname)
{
try
{
DataSet ds2 = b.GetDataSet("select mc from city where lx=2 and sjbh in (select id from city where lx=1 and mc='" + systemselectname + "')", "cspq2");
return ds2.Tables[0];
}
catch
{
return null;
}
}
}
我想实现城市的区县和片区联动(在同一个数据库中,通过上级编号sjbh 和类型lx区分)遇到的问题是:运行C#代码没有语法错误,但是没有小类可以选择(现在的小类只出现默认第一个大类对应的小类,没有选择)
前台有脚本错误,显示“ajaxtest未定义”就是这里:
<script language="javascript" type="text/javascript">
function GetTeamList()
{
var System=document.getElementById("SystemList");
ajaxtest.TeamName(System.value,TeamCallBack);}不知道是什么问题?(可能是别的地方有问题)怎么实现?谢谢!
解决方案 »
- 相关asp.net定时任务
- 请高手帮忙,如何用ASP.NET控制上传文件格式呢?
- 问一正则表达式 [急]
- GridView怎么通一个字段控制显示效果
- net 转化问题
- 小弟有个ID号,如何在SQL中判断与此表前3个记录是否重复,求教
- 请问怎样在Access的查询中用参数作为From的表名?
- System.Data.SqlClient.SqlException: 用户 'NSA_001\ASPNET' 登录失败
- 请问如何判断在Toolbar中点击的是哪一个按钮(vb)
- 大家可否将做B/S项目是,经常要考虑到的问题和经验总结一下。
- ASP.NET中button 的 onCommand传递参数
- html post 给 asp.net,只能在 Page_Load 中获取吗?能否触发 Button1_Click 事件。
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
</httpHandlers>
</system.web>
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
</httpHandlers>
1,在js调用的时候写类的全名,即包括命名空间
2.[AjaxPro.AjaxNamespace("test")]
public partial class ajaxtest : System.Web.UI.Page
config配置文件中没有引用。