Click here to Skip to main content
11,706,007 members (58,755 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# jQuery WebService
I have 2 dropdownlist and 1 textbox i m filling dropdown using webservice..
District DistrictCode
bangalore 1
chennai 2
mumbai 3
Two dropdownlist names are ddldistrict,ddltaluk( here ddldistrict is parent, ddltaluk is child)
textbox name is txtdistrictcode
if i selected ddldistrict like bangalore,chennai,mumbai that concerned districtid will bind in the txtdistrictcode textbox and concerned taluk will fill in the ddltaluk Let's say if i selected bangalore in ddldistrict for that bangalore id is 1 so 1 ll bind in the districtid textbox that is working fine.Now the problem is if i type 1 in ddldistrictid the concerned bangalore should bind in the ddldistrict that also working fine but the child textbox(ddltaluk) is not filling and it is disabled. But if i selected ddldistrict bangalore the districtid is binding and taluk is also filling.

I used jquery for bidirection binding( ddldistrict to txtdistrictid and txtdistrictid to ddldistrict)
$("#ContentPlaceHolder1_ddlDistrict").live("change", function () {
            var selectedText = $("#ContentPlaceHolder1_ddlDistrict option:selected").val();
            if (selectedText != "") {
            else if (selectedText == "") {
            else {
                alert('There is no Code for Selected District');
        $("#ContentPlaceHolder1_txtDistrict_Code_I").live("focusout", function () {
            var selectedText = $("#ContentPlaceHolder1_txtDistrict_Code_I").val();
            if (selectedText != "") {
                var selectedvalue = $("#ContentPlaceHolder1_ddlDistrict option:selected").val();
                if (selectedvalue == "") {
                    alert("Invalid District Code, Please Enter valid Code");
For Filling Cascading dropdownlist i used webservices:
Parent Control
        public  Ajx[] get_Districts(string knownCategoryValues, string category)
            DataTable dtMainModule = new DataTable();
            string StateID;
            StringDictionary MainModuleValues =  CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            StateID = "09";// MainModuleValues["StateID"];
            dtMainModule = odal.ReturnDt(@"select distinct fldDistrictCode,fldDistrictName from  bindDimpa.tblDistrict where fldStateID='" + StateID + "' order by fldDistrictName");
            List< Ajx> objMainModule = new List< Ajx>();
            foreach (DataRow dr in dtMainModule.Rows)
                objMainModule.Add(new  Ajx(Convert.ToString(dr["fldDistrictName"]), Convert.ToString(dr["fldDistrictCode"])));
            return objMainModule.ToArray();
Child Control
        public CascadingDropDownNameValue[] getTaluks(string knownCategoryValues, string category)
            DataTable dtMainModule = new DataTable();
            string fldDistrictID;
            StringDictionary MainModuleValues = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            fldDistrictID = MainModuleValues["DistrictID"];
            dtMainModule = odal.ReturnDt(@"select DISTINCT Dist_TehsilID,Tehsilaspercensus2001 from bindPS.tblVillage  where TehsilID is not null and DistrictID='" + fldDistrictID + "'");
            List<cascadingdropdownnamevalue> objMainModule = new List<cascadingdropdownnamevalue>();
            foreach (DataRow dr in dtMainModule.Rows)
                objMainModule.Add(new CascadingDropDownNameValue(Convert.ToString(dr["Tehsilaspercensus2001"]), Convert.ToString(dr["Dist_TehsilID"])));
            return objMainModule.ToArray();
Posted 26-Jun-13 2:45am
Edited 26-Jun-13 2:52am
(no name)3.2K

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

  Print Answers RSS
0 OriginalGriff 208
1 Sergey Alexandrovich Kryukov 142
2 Inimicos 60
3 ppolymorphe 57
4 ProgramFOX 50
0 OriginalGriff 9,037
1 Sergey Alexandrovich Kryukov 8,417
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,626

Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 26 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100