如何通过控件事件传递参数?

时间:2013-03-18 08:26:30

标签: c# asp.net events telerik dynamic-programming

需要使用此事件处理程序传递参数,是否可以使用事件处理程序发送参数?请检查我的RadTreeView2_NodeExpand语法。

internal void LoadTree(RadTreeView treeView, System.Collections.IEnumerable r)
{
   LoadRootNodes(ref treeView, TreeNodeExpandMode.ServerSideCallBack, r);
   treeView += RadTreeView2_NodeExpand(r);
}

public void RadTreeView2_NodeExpand(object sender, RadTreeNodeEventArgs e, System.Collections.IEnumerable r)
{                        
   if (e.Node.Nodes.Count == 0)
      PopulateNodeOnDemand(e, TreeNodeExpandMode.ServerSide, r);
}

private static void PopulateNodeOnDemand(RadTreeNodeEventArgs e, TreeNodeExpandMode expandMode, System.Collections.IEnumerable r)
{
   //List<testTable> data = GetChildNodes(e.Node.Value);

   foreach (testTable row in r)
   {
      RadTreeNode node = new RadTreeNode();
      node.Text = row.Address;//row["Title"].ToString();
      node.Value = row.ID; //row["CategoryId"].ToString();
      //if (Convert.ToInt32(row["ChildrenCount"]) > 0)
      //{
      //    node.ExpandMode = expandMode;
      //}
      e.Node.Nodes.Add(node);
   }

   e.Node.Expanded = true;
}       

private static void LoadRootNodes(ref RadTreeView treeView, TreeNodeExpandMode expandMode, System.Collections.IEnumerable data)
{
    //DataTable data = GetData(new SqlCommand("SELECT * FROM ProductCategories WHERE ParentId IS NULL"));

    foreach (testTable row in data)
    {
       RadTreeNode node = new RadTreeNode();
       node.Text = row.Address;//row["Title"].ToString();
       node.Value = row.ID;//row["CategoryId"].ToString();
       node.ExpandMode = expandMode;
       treeView.Nodes.Add(node);
    }
 }

如果有任何疑问,请询问,提前感谢任何类型的建议

3 个答案:

答案 0 :(得分:2)

不,您无法向现有事件添加参数。如果可以的话,你会如何传递一个值?

您已将row.ID存储在Value属性中,这是检索特定TreeNode信息的正确方法。因此,找到一种方法将数据存储在其他地方,并使其可以在RowId上访问。

答案 1 :(得分:1)

也许你可以尝试这样的事情。但请注意,您的Enumerable将受事件绑定约束。

internal void LoadTree(RadTreeView treeView, System.Collections.IEnumerable r)
    {
        var enumerable = r as object[] ?? r.Cast<object>().ToArray();
        LoadRootNodes(ref treeView, TreeNodeExpandMode.ServerSideCallBack, enumerable);
        treeView.NodeExpand += (s, e) =>
            {
             if (e.Node.Nodes.Count == 0)
               PopulateNodeOnDemand(e, 
                                    TreeNodeExpandMode.ServerSide,
                                    enumerable)
            };
    }

答案 2 :(得分:-1)

private void setup(string someData)
{
     Object.assignHandler((sender) => evHandler(sender,someData));
}
public void evHandler(Object sender, string someData)
{
    // need someData here!!!
}