Adding attributes with web service

3 posts, 0 answers
  1. Guss
    Guss avatar
    48 posts
    Member since:
    Apr 2008

    Posted 11 Oct 2008 Link to this post

    Hi there

        public RadTreeNodeData[] GetManufacturers(RadTreeNodeData node, object context)  
            IDictionary<string, object> contextDictionary = (IDictionary<string, object>)context;  
            String sql = "";  
            String parentname = "";  
            if (node.Value == "HardwareType")  
                sql = "SELECT 'Manufacturer' as [value], manufacturer as [text], hardwareType as [parentName] from tHardwareCatalog WHERE hardwareType = '" + node.Text + "' GROUP BY hardwareType, manufacturer ORDER BY manufacturer";  
            else if (node.Value == "Manufacturer")  

                parentname = node.Attributes["parentName"].ToString();  

                sql = "SELECT id as [value], model as [text], manufacturer as [parentName] from tHardwareCatalog WHERE hardwareType = '" + parentname +"' AND manufacturer = '" + node.Text + "' ORDER BY model";  
            SqlDataAdapter adapter = new SqlDataAdapter(sql, ConfigurationManager.ConnectionStrings["RemoteSqlServerData"].ConnectionString);  
            DataTable data = new DataTable();  
            List<RadTreeNodeData> result = new List<RadTreeNodeData>();  
            foreach (DataRow row in data.Rows)  
                RadTreeNodeData itemData = new RadTreeNodeData();  
                itemData.Text = row["text"].ToString();  
                itemData.Value = row["value"].ToString();  
                if (row["value"].ToString() == "Manufacturer")  
                    itemData.ExpandMode = TreeNodeExpandMode.WebService;  
            return result.ToArray();  

    When I create nodes with a web service, I also want to add attibutes to the node, so that I can read it some other stage.

    It does not seem to work."The given key was not present in the dictionary" Error.

    Please advise
  2. Veselin Vasilev
    Veselin Vasilev avatar
    2992 posts

    Posted 13 Oct 2008 Link to this post

    Hi Guss,

    Please try setting the Attributes of a node in this way:

    node.Attributes["attr1"] = "attr1 value from webservice"
    node.Attributes["attr2"] = "attr2 value from webservice"

    I hope this helps.

    Best wishes,
    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Guss
    Guss avatar
    48 posts
    Member since:
    Apr 2008

    Posted 13 Oct 2008 Link to this post

    Hi there, its actually the other way round.
    The web service to get the attribute from the selected node.

    But i've figured it out.

    In the web service I get it out of the context object (after making it a dictionary)


    String hardwaretype = (string)contextDictionary["hardwaretype"];
    String useinrefresh = (string)contextDictionary["useinrefresh"];
    String refreshgroup = (string)contextDictionary["refreshgroup"];

    and in the page, I pass the information into the context object:

    NodePopulatingCatalogId(sender, eventArgs)
        var node = eventArgs.get_node(); 
        var context = eventArgs.get_context(); 
        if (node.get_value() == "Manufacturer")
            var parentname = node.get_parent().get_text();  
    "parentname"] = parentname; 
        var hardwaretype = document.getElementById("<%= hardwaretype.ClientID %>"); 
        var useinrefresh = document.getElementById("<%= useinrefresh.ClientID %>"); 
        var refreshgroup = document.getElementById("<%= refreshgroup.ClientID %>"); 
    "hardwaretype"] = hardwaretype.value;
    "useinrefresh"] = useinrefresh.value; 
    "refreshgroup"] = refreshgroup.value; 

Back to Top