Post full code for webservice used in databinding webservice example?

2 posts, 1 answers
  1. KevinMc
    KevinMc avatar
    47 posts
    Member since:
    Dec 2006

    Posted 16 Jan 2008 Link to this post

    Can the full code for the webservice used in the online demo for binding prometheus menu to a webservice be posted. The stub does not help much for determining what we need to return from the webservice.
  2. Answer
    T. Tsonev
    Admin
    T. Tsonev avatar
    2809 posts

    Posted 17 Jan 2008 Link to this post

    Hello Kevin,

    The full code is available in the App_Code folder of the QSF - ProductCategories.cs. Here is the menu-related code:

    using System; 
    using System.Web; 
    using System.Collections; 
    using System.Collections.Generic; 
    using System.Collections.Specialized; 
    using System.Configuration; 
    using System.Data; 
    using System.Data.SqlClient; 
    using System.Threading; 
    using System.Web.Script.Services; 
    using System.Web.Services; 
    using System.Web.Services.Protocols; 
    using Telerik.Web.UI; 
     
     
    [ScriptService] 
    public class ProductCategories : WebService 
        [WebMethod] 
        public RadMenuItemData[] GetMenuCategories(RadMenuItemData item, object context) 
        { 
            IDictionary<stringobject> contextDictionary = (IDictionary<stringobject>) context; 
     
            DataTable productCategories = GetProductCategories(contextDictionary["CategoryID"]); 
     
            List<RadMenuItemData> result = new List<RadMenuItemData>(); 
     
            foreach (DataRow row in productCategories.Rows) 
            { 
                RadMenuItemData itemData = new RadMenuItemData(); 
                itemData.Text = row["Title"].ToString(); 
                itemData.Value = row["CategoryId"].ToString(); 
     
                if (Convert.ToInt32(row["ChildrenCount"]) > 0) 
                { 
                    itemData.ExpandMode = MenuItemExpandMode.WebService; 
                } 
     
                result.Add(itemData); 
            } 
     
            return result.ToArray(); 
        } 
     
        private DataTable GetProductCategories(object categoryId) 
        { 
            SqlConnection connection = new SqlConnection( 
                ConfigurationManager.ConnectionStrings["TelerikConnectionString"].ConnectionString); 
     
            SqlCommand selectCommand = 
                new SqlCommand( 
    @"
        SELECT
            pc1.CategoryID,
            pc1.Title,
            ISNULL(pc2.ChildrenCount, 0) as ChildrenCount
        FROM ProductCategories as pc1
        LEFT JOIN
            (
                SELECT   ParentId, COUNT(*) AS ChildrenCount
                FROM     ProductCategories
                Group By (ParentId)
            ) as pc2
        ON
            pc1.CategoryId = pc2.ParentId
        WHERE pc1.parentId = @parentId
    "
            connection); 
     
            selectCommand.Parameters.AddWithValue("parentId", categoryId); 
     
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommand); ; 
     
            DataTable productCategories = new DataTable(); 
            adapter.Fill(productCategories); 
     
            return productCategories; 
        } 
     
     


    Greetings,
    Tsvetomir Tsonev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top