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 = "http://tempuri.org/")]
[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();
}
}
}
-------------------------------------------------------------