This is a migrated thread and some comments may be shown as answers.

Adding attributes with web service

2 Answers 90 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Guss
Top achievements
Rank 2
Guss asked on 11 Oct 2008, 07:22 AM
Hi there

[WebMethod]  
    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();  
        adapter.Fill(data);  
        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();  
            itemData.Attributes.Add("parantName",row["parentName"].ToString());  
            if (row["value"].ToString() == "Manufacturer")  
            {  
                itemData.ExpandMode = TreeNodeExpandMode.WebService;  
            }  
            result.Add(itemData);  
        }  
        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 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 13 Oct 2008, 07:30 AM
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.
0
Guss
Top achievements
Rank 2
answered on 13 Oct 2008, 11:02 AM
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:

function
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();  
        context[
"parentname"] = parentname; 
    }
    var hardwaretype = document.getElementById("<%= hardwaretype.ClientID %>"); 
    var useinrefresh = document.getElementById("<%= useinrefresh.ClientID %>"); 
    var refreshgroup = document.getElementById("<%= refreshgroup.ClientID %>"); 
    context[
"hardwaretype"] = hardwaretype.value;
    context[
"useinrefresh"] = useinrefresh.value; 
    context[
"refreshgroup"] = refreshgroup.value; 
 }

Tags
TreeView
Asked by
Guss
Top achievements
Rank 2
Answers by
Veselin Vasilev
Telerik team
Guss
Top achievements
Rank 2
Share this question
or