locked
Help on cascading dropdownlist using ajax RRS feed

  • Question

  • User1173249824 posted

    Hi Pls I av been working on cascading a dropdownlist with ajax but the issue is I have completely finished with my coding, passing parameters, but the isue is that when ever I run my Webservices, and I invoked my bind state and City, it tels me that value cannot be null.

    here is my code:

    public class WebService : System.Web.Services.WebService {
         SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnectStrings"].ConnectionString);
       // Bind Archive
        
        [WebMethod]
        public CascadingDropDownNameValue[] BindArchive(string knownCategoryValues, string category) 
        {
           DataSet ds = new DataSet();
            conn.Open();//select * from [ST-Dep]
            SqlCommand cmd = new SqlCommand("select distinct empd.arc, empc.EmpCategoryId,empc.EmpCategoryName from Doc empd INNER JOIN EmpCategory empc On empd.arc = empc.EmpCategoryId", conn);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            cmd.ExecuteNonQuery();
            adp.Fill(ds);
            conn.Close();
    
            List<CascadingDropDownNameValue> ArchiveDetails = new List<CascadingDropDownNameValue> ();
            foreach (DataRow Dr in ds.Tables[0].Rows)
            {
                string ArcID = Dr["arc"].ToString();
                string ArcName = Dr["EmpCategoryName"].ToString();
    
                ArchiveDetails.Add(new CascadingDropDownNameValue(ArcName, ArcID));
    
        }
        return ArchiveDetails.ToArray();
    }
        //Folder
        [WebMethod]
        public CascadingDropDownNameValue[] BindFolder(string knownCategoryValues, string category)
        {
        DataSet ds = new DataSet();
        char ArcID;
        StringDictionary ArchiveDetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        ArcID = Convert.ToChar(ArchiveDetails["arc"]);
        conn.Open();//SELECT  * From [ST-Dep] where DepId=@DepId
        SqlCommand cmd = new SqlCommand("select distinct empd.folder,dep.DepId,dep.DepName From Doc empd INNER JOIN [ST-Dep] dep ON empd.folder = dep.DepId where empd.archive= @DepId ", conn);
        cmd.Parameters.AddWithValue("@DepId", ArcID);
        cmd.ExecuteNonQuery();
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            adp.Fill(ds);
            conn.Close();
             List<CascadingDropDownNameValue> FolderDetails = new List<CascadingDropDownNameValue> ();
            foreach (DataRow Dr in ds.Tables[0].Rows)
            {
                string FolderID = Dr["folder"].ToString();
                string FolderName = Dr["DepName"].ToString();
                FolderDetails.Add(new CascadingDropDownNameValue(FolderName, FolderID));
            }
            return FolderDetails.ToArray();
            }
        //SubFolder bind
        [WebMethod]
        public CascadingDropDownNameValue[] BinSubfolder(string knownCategoryValues, string category)
        {
            DataSet ds = new DataSet();
            char FolderID;
            StringDictionary folderdetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            FolderID = Convert.ToChar(folderdetails["DepName"]);
            conn.Open();//Select * From Doc where folder = @Folder
            SqlCommand cmd = new SqlCommand("select distinct empd.subfolder, trad.TradeId, trad.TradeName From Doc empd INNER JOIN [Trade] trad ON empd.subfolder = trad.TradeId where (empd.folder = @Folder)", conn);
            cmd.Parameters.AddWithValue("@Folder", FolderID);
            cmd.ExecuteNonQuery();
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            adp.Fill(ds);
            conn.Close();
            List<CascadingDropDownNameValue> SubFoldetails = new List<CascadingDropDownNameValue>();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string SubFolID = dr["subfolder"].ToString();
                string subFolName = dr["TradeName"].ToString(); 
    SubFoldetails.Add(new CascadingDropDownNameValue(subFolName, SubFolID)); } return SubFoldetails.ToArray(); } }

    and Here is my Category in my CASCADINGDROPDOWN
    <asp:CascadingDropDown ID="ccarchive" runat="server" Category="arc" TargetControlID="ddarchive" LoadingText="Loading Archives.." PromptText="Select Archive" ServiceMethod="BindArchive" ServicePath="~/WebService.asmx"   />
    
      <asp:CascadingDropDown ID="ccFolder" runat="server" Category="DepId" TargetControlID="ddFolder" ParentControlID="ddarchive" LoadingText="Loading Folders.." PromptText="Select Folder" ServiceMethod="BindFolder" ServicePath="~/WebService.asmx" />
    
     <asp:CascadingDropDown ID="ccSubfolder" runat="server" Category ="TradeId"  TargetControlID ="ddSubfolder" ParentControlID ="ddFolder" LoadingText="Loading SubFolders" PromptText ="Select SubFolder" ServiceMethod="BindSubfolder" ServicePath="~/WebService.asmx"/>  
           

    Ps can som1 elp me out with what might av been causing it to retun a null value

    Thanks

    Saturday, April 18, 2015 9:39 AM

Answers

  • User1814019480 posted

    hi Alamdreal,

    According to your code, it seems that your code is nothing wrong. But I am not totally understanding your meaning that " I invoked my bind state and City, it tels me that value cannot be null."

    Form your description and code, there is not any information about your state and city property for binding data to dropdownlist. Would you like to share more details about which step or some where you occurred this error. I think it will be very helpful for our further support. At the same time, I recommend you refer to this document about how to use cascading dropdownlist with database demo:

    http://www.ajaxcontroltoolkit.com/Walkthrough/CCDWithDB.aspx

    Regards,
    Will

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 20, 2015 1:32 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 21, 2015 8:29 AM

All replies

  • User1814019480 posted

    hi Alamdreal,

    According to your code, it seems that your code is nothing wrong. But I am not totally understanding your meaning that " I invoked my bind state and City, it tels me that value cannot be null."

    Form your description and code, there is not any information about your state and city property for binding data to dropdownlist. Would you like to share more details about which step or some where you occurred this error. I think it will be very helpful for our further support. At the same time, I recommend you refer to this document about how to use cascading dropdownlist with database demo:

    http://www.ajaxcontroltoolkit.com/Walkthrough/CCDWithDB.aspx

    Regards,
    Will

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 20, 2015 1:32 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 21, 2015 8:29 AM