猿问

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

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

 

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

 

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

繁花如伊

卡断点调试、看sql语句执行查询到没有、在就是看控件设定是不是正确
随时随地看视频慕课网APP
我要回答