Click here to Skip to main content
12,077,753 members (48,993 online)
Rate this:
 
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 != "") {
                $('#ContentPlaceHolder1_txtDistrict_Code_I').val(selectedText);
            }
            else if (selectedText == "") {
                $('.ajax__validatorcallout_popup_table_row').hide();
                $('#ContentPlaceHolder1_ddlDistrict').focus();
                $('#ContentPlaceHolder1_txtDistrict_Code_I').val('');
            }
            else {
                $('#ContentPlaceHolder1_txtDistrict_Code_I').val('');
                $('#ContentPlaceHolder1_ddlDistrict').val('');
                alert('There is no Code for Selected District');
                $('#ContentPlaceHolder1_ddlDistrict').focus();
            }
        });
 
        $("#ContentPlaceHolder1_txtDistrict_Code_I").live("focusout", function () {
            var selectedText = $("#ContentPlaceHolder1_txtDistrict_Code_I").val();
            if (selectedText != "") {
                $('#ContentPlaceHolder1_ddlDistrict').val(selectedText);
                var selectedvalue = $("#ContentPlaceHolder1_ddlDistrict option:selected").val();
                if (selectedvalue == "") {
                    alert("Invalid District Code, Please Enter valid Code");
                    $("#ContentPlaceHolder1_txtDistrict_Code_I").val('');
                    $("#ContentPlaceHolder1_txtDistrict_Code_I").focus();
                }
            }
        });
For Filling Cascading dropdownlist i used webservices:
Parent Control
[WebMethod]
        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
 
[WebMethod]
        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();
        }</cascadingdropdownnamevalue>
Posted 26-Jun-13 3:45am
HRVP353
Edited 26-Jun-13 3:52am
RelicV3.7K
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160212.1 | Last Updated 26 Jun 2013
Copyright © CodeProject, 1999-2016
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