for design page of your aspx page paste the below code
<table>
<tr>
<td>
Select Country:
</td>
<td>
<asp:DropDownList runat="server" ID="ddlcountry">
</asp:DropDownList>
<asp:CascadingDropDown ID="CascadingDropDown1" TargetControlID="ddlcountry" Category="country"
PromptText="Select Country" LoadingText="Please Wait..." ServiceMethod="GETCOUNTRY"
runat="server">
</asp:CascadingDropDown>
</td>
</tr>
<tr>
<td>
Select State:
</td>
<td>
<asp:DropDownList runat="server" ID="ddlstate">
</asp:DropDownList>
<asp:CascadingDropDown ID="CascadingDropDown2" TargetControlID="ddlstate" Category="state"
PromptText="Select State" LoadingText="Please Wait..." ServiceMethod="GETSTATE"
runat="server" ParentControlID="ddlcountry">
</asp:CascadingDropDown>
</td>
</tr>
<tr>
<td>
Select City:
</td>
<td>
<asp:DropDownList runat="server" ID="ddlcity">
</asp:DropDownList>
<asp:CascadingDropDown ID="CascadingDropDown3" TargetControlID="ddlcity" Category="city"
PromptText="Select City" LoadingText="Please Wait..." ServiceMethod="GETCITY"
runat="server" ParentControlID="ddlstate">
</asp:CascadingDropDown>
</td>
</tr>
</table>
& code behind this page paste below code:
[System.Web.Services.WebMethod]
public static CascadingDropDownNameValue[] GETCOUNTRY(string knownCategoryValues, string category)
{
//Fill your dt from database
dt = //your dt
List<CascadingDropDownNameValue> oq = new List<CascadingDropDownNameValue>();
for (int i = 0; i < dt.Rows.Count; i++)
{
oq.Add(new CascadingDropDownNameValue(dt.Rows[i]["country_name"].ToString(), dt.Rows[i]["country_id"].ToString()));
}
return oq.ToArray();
}
[System.Web.Services.WebMethod]
public static CascadingDropDownNameValue[] GETSTATE(string knownCategoryValues, string category)
{
StringDictionary countrydetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
int countryID = Convert.ToInt32(countrydetails["country"]);
//Fill your dt from database
dt = //your dt
List<CascadingDropDownNameValue> oq = new List<CascadingDropDownNameValue>();
for (int i = 0; i < dt.Rows.Count; i++)
{
oq.Add(new CascadingDropDownNameValue(dt.Rows[i]["state_name"].ToString(), dt.Rows[i]["state_id"].ToString()));
}
return oq.ToArray();
}
[System.Web.Services.WebMethod]
public static CascadingDropDownNameValue[] GETCITY(string knownCategoryValues, string category)
{
StringDictionary countrydetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
int stateID = Convert.ToInt32(countrydetails["state"]);
//Fill your dt from database
dt = //your dt
List<CascadingDropDownNameValue> oq = new List<CascadingDropDownNameValue>();
for (int i = 0; i < dt.Rows.Count; i++)
{
oq.Add(new CascadingDropDownNameValue(dt.Rows[i]["city_name"].ToString(), dt.Rows[i]["state_id"].ToString()));
}
return oq.ToArray();
}
<table>
<tr>
<td>
Select Country:
</td>
<td>
<asp:DropDownList runat="server" ID="ddlcountry">
</asp:DropDownList>
<asp:CascadingDropDown ID="CascadingDropDown1" TargetControlID="ddlcountry" Category="country"
PromptText="Select Country" LoadingText="Please Wait..." ServiceMethod="GETCOUNTRY"
runat="server">
</asp:CascadingDropDown>
</td>
</tr>
<tr>
<td>
Select State:
</td>
<td>
<asp:DropDownList runat="server" ID="ddlstate">
</asp:DropDownList>
<asp:CascadingDropDown ID="CascadingDropDown2" TargetControlID="ddlstate" Category="state"
PromptText="Select State" LoadingText="Please Wait..." ServiceMethod="GETSTATE"
runat="server" ParentControlID="ddlcountry">
</asp:CascadingDropDown>
</td>
</tr>
<tr>
<td>
Select City:
</td>
<td>
<asp:DropDownList runat="server" ID="ddlcity">
</asp:DropDownList>
<asp:CascadingDropDown ID="CascadingDropDown3" TargetControlID="ddlcity" Category="city"
PromptText="Select City" LoadingText="Please Wait..." ServiceMethod="GETCITY"
runat="server" ParentControlID="ddlstate">
</asp:CascadingDropDown>
</td>
</tr>
</table>
& code behind this page paste below code:
[System.Web.Services.WebMethod]
public static CascadingDropDownNameValue[] GETCOUNTRY(string knownCategoryValues, string category)
{
//Fill your dt from database
dt = //your dt
List<CascadingDropDownNameValue> oq = new List<CascadingDropDownNameValue>();
for (int i = 0; i < dt.Rows.Count; i++)
{
oq.Add(new CascadingDropDownNameValue(dt.Rows[i]["country_name"].ToString(), dt.Rows[i]["country_id"].ToString()));
}
return oq.ToArray();
}
[System.Web.Services.WebMethod]
public static CascadingDropDownNameValue[] GETSTATE(string knownCategoryValues, string category)
{
StringDictionary countrydetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
int countryID = Convert.ToInt32(countrydetails["country"]);
//Fill your dt from database
dt = //your dt
List<CascadingDropDownNameValue> oq = new List<CascadingDropDownNameValue>();
for (int i = 0; i < dt.Rows.Count; i++)
{
oq.Add(new CascadingDropDownNameValue(dt.Rows[i]["state_name"].ToString(), dt.Rows[i]["state_id"].ToString()));
}
return oq.ToArray();
}
[System.Web.Services.WebMethod]
public static CascadingDropDownNameValue[] GETCITY(string knownCategoryValues, string category)
{
StringDictionary countrydetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
int stateID = Convert.ToInt32(countrydetails["state"]);
//Fill your dt from database
dt = //your dt
List<CascadingDropDownNameValue> oq = new List<CascadingDropDownNameValue>();
for (int i = 0; i < dt.Rows.Count; i++)
{
oq.Add(new CascadingDropDownNameValue(dt.Rows[i]["city_name"].ToString(), dt.Rows[i]["state_id"].ToString()));
}
return oq.ToArray();
}
Thank You ............
ReplyDelete