Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
am using ajax cascading dropdownlist when the page gets load i want the dropdownlist should be selected to the country which i had store in database instead of select country option what i should do for it this is my code


public CascadingDropDownNameValue[] GetCountry(string knownCategoryValues, string category)
        {

            MNBusinessLogic.Admin adm = new MNBusinessLogic.Admin();
            DataSet dsUpdate = adm.GetMasters(0, "Country", 0, true, false);
            List<CascadingDropDownNameValue> countrydetails = new List<CascadingDropDownNameValue>();
            if (dsUpdate != null && dsUpdate.Tables.Count > 0 && dsUpdate.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dtrow in dsUpdate.Tables[0].Rows)
                {
                    string CountryID = dtrow["uid"].ToString();
                    string CountryName = dtrow["MasterKey"].ToString();
                    countrydetails.Add(new CascadingDropDownNameValue(CountryName, CountryID));
                }
                
            }
            return countrydetails.ToArray();
        }

and aspx code is

 <asp:DropDownList ID="ddlC" runat="server">
         </asp:DropDownList>
          <ajaxToolkit:CascadingDropDown ID="cascadingddlC"  runat="server"                        TargetControlID="ddlC" PromptText="Select Country" LoadingText="Loading" Category="Country" ServiceMethod="GetCountry"  ServicePath="cascadingHelper.asmx">
               </ajaxToolkit:CascadingDropDown>
Posted

1 solution

i got the answer i had to just add a line of code

cascadingddlC.SelectedValue = ds1.Tables[0].Rows[0]["Country"].ToString();
 
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