CascaddingDropDown Database Example Help

Last post 12-29-2006 5:16 PM by JimAmigo. 0 replies.

Sort Posts:

  • CascaddingDropDown Database Example Help

    12-29-2006, 5:16 PM
    • Member
      581 point Member
    • JimAmigo
    • Member since 01-28-2004, 8:40 AM
    • Posts 252

    Can someone help me modify the page method code from the XML example to work with the database example walk through? (http://ajax.asp.net/ajaxtoolkit/Walkthrough/CCDWithDB.aspx) These seems like an important not presented in the walkthrough.
    My app has only two dropdownlists instead of three in the example.  Parent DropDownList should use the GetContractors method, It returns all Contractors (shortdescription) and ContractorID
    The second dropdownlist returns all JobTitles for a specific Contractor, each job title has a corresponding contractorid. This child dropdown should use the GetJobTitlesForContractor(contractorID) method with contractorID as the parameter, returning the JobTitle and JobTitleID
    Here is the XML example page method code..

    <script runat="server">
            [System.Web.Services.WebMethod]
            [System.Web.Script.Services.ScriptMethod]
            public static AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents_PageMethod(string knownCategoryValues, string category)
            {
                AjaxControlToolkit.CascadingDropDownNameValue[] values = new CarsService().GetDropDownContents(knownCategoryValues, category);

                values[1].isDefaultValue = true;
                return values;
            }
    </script>
     

    Here is my webservice...

    using System;
    using System.Web;
    using System.Collections;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using AjaxControlToolkit;
    using System.Data;
    using System.Data.SqlClient;

     

    /// <summary>
    /// Summary description for JobTitlesService
    /// </summary>
    [WebService(Namespace = "
    http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class JobTitlesService : System.Web.Services.WebService {

        public JobTitlesService ()

       {
        //Uncomment the following line if using designed components
        //InitializeComponent();
      }

      [WebMethod]
        public CascadingDropDownNameValue[] GetContractors(
        string knownCategoryValues,
        string category)
      {
          BMSDataTableAdapters.ContractorsTableAdapter contractorAdapter =
          new BMSDataTableAdapters.ContractorsTableAdapter();
          BMSData.ContractorsDataTable contractors = contractorAdapter.GetContractors();
            List<CascadingDropDownNameValue> values =
             new List<CascadingDropDownNameValue>();
          foreach (DataRow dr in contractors)
          {
              string contractor = (string)dr["ShortDescription"];
              int contractorID = (int)dr["ContractorID"];
              values.Add(new CascadingDropDownNameValue(             
                  contractor, contractorID.ToString()));
          }
          return values.ToArray();

      }

      [WebMethod]
      public CascadingDropDownNameValue[] GetJobTitlesForContractor(
        string knownCategoryValues,
        string category)
      {
        StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(
          knownCategoryValues);
        int contractorID;
        if (!kv.ContainsKey("ShortDescription") ||
            !Int32.TryParse(kv["ShortDescription"], out contractorID))
        {
          return null;
        }

        BMSDataTableAdapters.JobTitlesTableAdapter jobtitlesAdapter =
            new BMSDataTableAdapters.JobTitlesTableAdapter();
        BMSData.JobTitlesDataTable jobtitles =
            jobtitlesAdapter.GetJobTitlesForContractor(contractorID);
        List<CascadingDropDownNameValue> values =
          new List<CascadingDropDownNameValue>();
        foreach (DataRow dr in jobtitles)
        {
            values.Add(new CascadingDropDownNameValue(
              (string)dr["JobTitle"], dr["JobTitleID"].ToString()));
        }
        return values.ToArray();

      } 
      
    }

    Jim
Page 1 of 1 (1 items)