Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
}

}
}


-------------------------------------------------------------
Posted
Updated 27-Apr-10 6:26am
v2

1 solution

Your asmx is at the root ? Have you tried putting a full URL instead of just the service name in your aspx ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900