首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

关于Ajax拓展控件CascadingDropDown级联下拉控件的有关问题

2012-05-30 
关于Ajax拓展控件CascadingDropDown级联下拉控件的问题HTML codeasp:ScriptManager IDScriptManager1

关于Ajax拓展控件CascadingDropDown级联下拉控件的问题

HTML code
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true" EnableScriptLocalization="true">    </asp:ScriptManager>       <table style="width: 100%;">        <tr>            <td>新闻类别:</td>            <td>                <asp:DropDownList ID="DropDownList1" runat="server">                </asp:DropDownList>                <ajax:CascadingDropDown ID="DropDownList1_CascadingDropDown" runat="server"                     Enabled="True" TargetControlID="DropDownList1" Category="category" PromptText="请选择一个新闻类别" LoadingText="载入中..." ScriptPath="MyCascadingWebService.asmx" ServiceMethod="GetNewCate">                </ajax:CascadingDropDown>            </td>        </tr>        <tr>            <td>新闻标题:</td>            <td>                <asp:DropDownList ID="DropDownList2" runat="server">                </asp:DropDownList>               <ajax:CascadingDropDown ID="DropDownList2_CascadingDropDown" runat="server"                     Enabled="True" TargetControlID="DropDownList2" Category="title" PromptText="请选择一个新闻标题" LoadingText="载入中..." ScriptPath="MyCascadingWebService.asmx" ServiceMethod="GetNewTitle" ParentControlID="DropDownList1">                </ajax:CascadingDropDown>            </td>        </tr>    </table>

WebService
C# code
using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Linq;using System.Web;using System.Web.Services;using System.Web.Services.Protocols;using System.Xml.Linq;using AjaxControlToolkit;using System.Collections.Generic;using System.Data.SqlClient;using System.Collections.Specialized;namespace Ajax扩展控件{    /// <summary>    /// MyCascadingWebService 的摘要说明    /// </summary>    [WebService(Namespace = "http://tempuri.org/")]    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]    [ToolboxItem(false)]    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。    [System.Web.Script.Services.ScriptService]    public class MyCascadingWebService : System.Web.Services.WebService    {        [WebMethod]        public CascadingDropDownNameValue[] GetNewCate(string knownCategoryValues, string category)        {            List<CascadingDropDownNameValue> list = new List<CascadingDropDownNameValue>();            SqlConnection myCon = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=newsystem;Integrated Security=True");            myCon.Open();            SqlCommand myCmd = new SqlCommand("select name,id from catepory", myCon);            SqlDataReader myDR = myCmd.ExecuteReader();            while (myDR.Read())            {                list.Add(new CascadingDropDownNameValue(myDR["name"].ToString(), myDR["id"].ToString()));            }            myCon.Close();            myDR.Close();            return list.ToArray();        }        [WebMethod]        public CascadingDropDownNameValue[] GetNewTitle(string knownCategoryValues, string category)        {            List<CascadingDropDownNameValue> list = new List<CascadingDropDownNameValue>();            StringDictionary sdc = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);            if (!sdc.ContainsKey("name"))            {                return null;            }            SqlConnection myCon = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=newsystem;Integrated Security=True");            myCon.Open();            string cateid = sdc["name"];            SqlCommand myCmd = new SqlCommand("select title,id from news where cateid=@cateid", myCon);            myCmd.Parameters.AddWithValue("@cateid", cateid);            SqlDataReader myDR = myCmd.ExecuteReader();            while (myDR.Read())            {                list.Add(new CascadingDropDownNameValue(myDR["title"].ToString(), myDR["id"].ToString()));            }            myCon.Close();            myDR.Close();            return list.ToArray();        }    }} 


运行时出错提示:
1.Uncaught syntaxError:Unexpected token < 说是MyCascadingWebService.asmx 3行 字符1 有语法错误
2.Sys.ArgumentUndefinedException:值不能是未定义的。参数名:type 是出自ScriptResource.axd?d=*****&t=******

[解决办法]
IT'S NOT ScriptPath。IT'S ServicePath。

热点排行