ASP.NET AJAX CascadingDropDown如何使用帮助:“方法错误500" [英] ASP.NET AJAX CascadingDropDown How-to help: "method error 500"

查看:117
本文介绍了ASP.NET AJAX CascadingDropDown如何使用帮助:“方法错误500"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我选择一个国家/地区,则表示我有一个类似的州,并且如果我选择州/地区,则抛出诸如方法错误500"之类的错误,我有Country,State,City下拉列表

--------------------------------
我的aspx页面



< asp:DropDownList ID =" ddlcountry" runat =服务器">
</asp:DropDownList>
< asp:DropDownList ID =" ddlstate" runat =服务器">
</asp:DropDownList>
< asp:DropDownList ID =“ ddlcity" runat =服务器">
</asp:DropDownList>
< cc1:CascadingDropDown ID ="CascadingDropDown1"; runat =服务器" TargetControlID ="ddlcountry"
PromptText ="SelectCountry";类别=国家/地区" ServicePath ="DropDownList.asmx"
ServiceMethod ="GetCountry">
</cc1:CascadingDropDown>
< cc1:CascadingDropDown ID ="CascadingDropDown2"; runat =服务器" TargetControlID ="ddlstate"
PromptText ="SelectState". ParentControlID ="ddlcountry".类别=状态". ServicePath ="DropDownList.asmx"
ServiceMethod =" GetState">
</cc1:CascadingDropDown>
< cc1:CascadingDropDown ID ="CascadingDropDown3"; runat =服务器" TargetControlID ="ddlcity"
PromptText ="SelectCity". ParentControlID ="ddlstate".类别=城市" ServicePath =〜/DropDownList.asmx"
ServiceMethod =" GetCity">
</cc1:CascadingDropDown>

-------------------------------------------------- -----------
使用系统;
使用System.Collections;
使用System.ComponentModel;
使用System.Data;
使用System.Linq;
使用System.Web;
使用System.Web.Services;
使用System.Web.Services.Protocols;
使用System.Xml.Linq;
使用System.Data.SqlClient;
使用System.Configuration;
使用AjaxControlToolkit;
使用System.Collections.Specialized;
使用System.Collections.Generic;
使用DAL;
使用System.Web.Script.Services;

命名空间Hospital_3_Tier
{
[WebService(Namespace =& quot; http://tempuri.org/& quot;))]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//[ToolboxItem(false)]
//要允许使用ASP.NET AJAX从脚本中调用此Web服务,请取消注释以下行.
[System.Web.Script.Services.ScriptService()]

公共类DropDownList:System.Web.Services.WebService
{

[WebMethod]
公共CascadingDropDownNameValue [] GetCountry(字符串knownCategoryValues,字符串类别)<​​br/> {

字符串web_Conn = ConfigurationSettings.AppSettings ["conn"].ToString();

SqlConnection con =新的SqlConnection(web_Conn);

字符串str_Cmd ="SELECT * FROM tblcountry";


SqlDataAdapter da =新的SqlDataAdapter(str_Cmd,con);
DataSet ds = new DataSet();
con.Open();
da.Fill(ds);
con.Close();

列表< CascadingDropDownNameValue> lst_Country =新列表< CascadingDropDownNameValue>();


foreach(ds.Tables [0] .Rows中的DataRow dr)
{
lst_Country.Add(新的CascadingDropDownNameValue(dr ["countryname"].ToString(),dr ["countryid"].ToString()));
}
返回lst_Country.ToArray();
}


[WebMethod]

公共CascadingDropDownNameValue [] GetState(字符串knownCategoryValues,字符串类别)<​​br/> {


StringDictionary countyValues = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

int CountryID;

//这里的***国家" ***是CascadingDropDown的类别
CountryID = Convert.ToInt32(countyValues ["Country"]]);


字符串web_Conn = ConfigurationSettings.AppSettings ["conn"].ToString();

SqlConnection con =新的SqlConnection(web_Conn);

字符串str_Cmd ="SELECT * FROM tblstate WHERE countryid =" + CountryID;


SqlDataAdapter da =新的SqlDataAdapter(str_Cmd,con);
DataSet ds = new DataSet();
con.Open();
da.Fill(ds);
con.Close();

列表< CascadingDropDownNameValue> lst_State =新列表< CascadingDropDownNameValue>();

foreach(ds.Tables [0] .Rows中的DataRow dr)
{
lst_State.Add(新的CascadingDropDownNameValue(dr ["statename"].ToString(),dr ["stateid"].ToString()));
}
返回lst_State.ToArray();
}


[WebMethod]

公共CascadingDropDownNameValue [] GetCity(字符串KnownCategoryValues,字符串类别)<​​br/> {


StringDictionary stateValue = CascadingDropDown.ParseKnownCategoryValuesString(KnownCategoryValues);

int StateID;

//这里***州" ***是CascadingDropDown的类别

StateID = Convert.ToInt32(stateValue ["State"]);

字符串web_Conn = ConfigurationSettings.AppSettings ["conn"].ToString();

SqlConnection con =新的SqlConnection(web_Conn);

字符串str_Cmd ="SELECT * FROM tblcity WHERE stateid =" + StateID;

SqlDataAdapter da =新的SqlDataAdapter(str_Cmd,con);
DataSet ds = new DataSet();
con.Open();
da.Fill(ds);
con.Close();

列表< CascadingDropDownNameValue> lst_City =新列表< CascadingDropDownNameValue>();

foreach(ds.Tables [0] .Rows中的DataRow dr)
{
lst_City.Add(新的CascadingDropDownNameValue(dr ["cityname"].ToString(),dr ["cityid"].ToString()));
}
返回lst_City.ToArray();
}

}
}


-------------------------------------------------- -----------

I have Country,State,City Dropdownlist if i select one country means i got a similar states and i select state means throw a error like this "method error 500"


--------------------------------
My aspx page



<asp:DropDownList ID="ddlcountry" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="ddlstate" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="ddlcity" runat="server">
</asp:DropDownList>
<cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="ddlcountry"
PromptText="SelectCountry" Category="Country" ServicePath="DropDownList.asmx"
ServiceMethod="GetCountry">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="ddlstate"
PromptText="SelectState" ParentControlID="ddlcountry" Category="State" ServicePath="DropDownList.asmx"
ServiceMethod="GetState">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="CascadingDropDown3" runat="server" TargetControlID="ddlcity"
PromptText="SelectCity" ParentControlID="ddlstate" Category="City" ServicePath="~/DropDownList.asmx"
ServiceMethod="GetCity">
</cc1: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 System.Data.SqlClient;
using System.Configuration;
using AjaxControlToolkit;
using System.Collections.Specialized;
using System.Collections.Generic;
using DAL;
using System.Web.Script.Services;

namespace Hospital_3_Tier
{
[WebService(Namespace = &quot;http://tempuri.org/&quot;)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//[ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService()]

public class DropDownList : System.Web.Services.WebService
{

[WebMethod]
public CascadingDropDownNameValue[] GetCountry(string knownCategoryValues, string category)
{

string web_Conn = ConfigurationSettings.AppSettings["conn"].ToString();

SqlConnection con = new SqlConnection(web_Conn);

string str_Cmd = "SELECT * FROM tblcountry";


SqlDataAdapter da = new SqlDataAdapter(str_Cmd, con);
DataSet ds = new DataSet();
con.Open();
da.Fill(ds);
con.Close();

List<CascadingDropDownNameValue> lst_Country = new List<CascadingDropDownNameValue>();


foreach (DataRow dr in ds.Tables[0].Rows)
{
lst_Country.Add(new CascadingDropDownNameValue(dr["countryname"].ToString(), dr["countryid"].ToString()));
}
return lst_Country.ToArray();
}


[WebMethod]

public CascadingDropDownNameValue[] GetState(string knownCategoryValues, string category)
{


StringDictionary countyValues = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

int CountryID;

// Here *** "Country" *** is Category of CascadingDropDown
CountryID = Convert.ToInt32(countyValues["Country"]);


string web_Conn = ConfigurationSettings.AppSettings["conn"].ToString();

SqlConnection con = new SqlConnection(web_Conn);

string str_Cmd = "SELECT * FROM tblstate WHERE countryid=" + CountryID;


SqlDataAdapter da = new SqlDataAdapter(str_Cmd, con);
DataSet ds = new DataSet();
con.Open();
da.Fill(ds);
con.Close();

List<CascadingDropDownNameValue> lst_State = new List<CascadingDropDownNameValue>();

foreach (DataRow dr in ds.Tables[0].Rows)
{
lst_State.Add(new CascadingDropDownNameValue(dr["statename"].ToString(), dr["stateid"].ToString()));
}
return lst_State.ToArray();
}


[WebMethod]

public CascadingDropDownNameValue[] GetCity(string KnownCategoryValues, string category)
{


StringDictionary stateValue = CascadingDropDown.ParseKnownCategoryValuesString(KnownCategoryValues);

int StateID;

// Here *** "State" *** is Category of CascadingDropDown

StateID = Convert.ToInt32(stateValue["State"]);

string web_Conn = ConfigurationSettings.AppSettings["conn"].ToString();

SqlConnection con = new SqlConnection(web_Conn);

string str_Cmd = "SELECT * FROM tblcity WHERE stateid=" + StateID;

SqlDataAdapter da = new SqlDataAdapter(str_Cmd, con);
DataSet ds = new DataSet();
con.Open();
da.Fill(ds);
con.Close();

List<CascadingDropDownNameValue> lst_City = new List<CascadingDropDownNameValue>();

foreach (DataRow dr in ds.Tables[0].Rows)
{
lst_City.Add(new CascadingDropDownNameValue(dr["cityname"].ToString(), dr["cityid"].ToString()));
}
return lst_City.ToArray();
}

}
}


-------------------------------------------------------------

推荐答案

您的asmx是根目录吗?您是否尝试过将完整的URL而不只是服务名称放在aspx中?
Your asmx is at the root ? Have you tried putting a full URL instead of just the service name in your aspx ?


这篇关于ASP.NET AJAX CascadingDropDown如何使用帮助:“方法错误500"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆