首页 新闻 会员 周边

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

0
悬赏园豆:20 [已解决问题] 解决于 2010-11-05 18:41

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

何塞穆里尼奥的主页 何塞穆里尼奥 | 初学一级 | 园豆:126
提问于:2010-10-10 19:17
< >
分享
最佳答案
0

这些控件写过一篇就不用了,在实际项目中很少用,以前写过一篇文章。

http://www.cnblogs.com/xlovey/archive/2007/11/16/961089.html

收获园豆:10
Astar | 高人七级 |园豆:40805 | 2010-10-10 21:57
其他回答(1)
0

卡断点调试、看sql语句执行查询到没有、在就是看控件设定是不是正确

收获园豆:10
悠悠思丶 | 园豆:189 (初学一级) | 2010-10-10 19:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册