日期:2014-05-17  浏览次数:20574 次

关于AjaxPro实现DropDownList二级无刷新联动的一点问题?
HTML code

<%@ 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

    pub



后台:

C# code

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);

}

不知道是什么问题?(可能是别的地方有问题)怎么实现?谢谢!

------解决方案--------------------
Web.config

<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
</httpHandlers>
 </system.web>
------解决方案--------------------
探讨
Web.config

<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory,