如何获取通过页面加载复选框选择的treenode值. [英] How to get treenode values selected through check boxes on page load.

查看:61
本文介绍了如何获取通过页面加载复选框选择的treenode值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在建立基于xml的treeview,我将通过treeview中的复选框选择节点.现在,当我单击提交按钮时,在下一页中,我将在gridview中绑定值,该值是在私有页面中选择treeview节点的.我要求对此提供帮助.

谢谢
Mahesh.

Hi,

I am building the treeview based on xml and i will selecte the nodes by through the checkboxes in treeview. Now when i click the submit button, in next page i am binding the values in gridview which i selected the treeview nodes in privious page. I request please help me on this.

Thanks
Mahesh.

推荐答案

这是您应该能够执行的操作.

(我创建了示例,假设您需要在GridView中显示一些选定的Person 对象).您只需要根据需要更改以下代码:

Here is how you should be able to do it.

(I created the example assuming you need to show some selected Person objects in the GridView). You just need to change the following code according to your need:

/// <summary>
/// Load the selected persons in the GridView
/// </summary>
private void LoadPersons()
{
       List<Person> persons = new List<Person>();
       foreach (TreeNode node in TreeView1.CheckedNodes)
       {
           string Value = node.Value; //Value could be an Id of the data
           int Id = Convert.ToInt32(Value);
           string Text = node.Text; //Text is displayed as the node value
           string path = node.ValuePath; // Path of the node from the Root Node
           Person person = GetPersonById(Id);
           if (person != null)
           {
               persons.Add(person);
           }
       }
       GridView1.DataSource = persons;
       GridView1.DataBind();
}


这篇关于如何获取通过页面加载复选框选择的treenode值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆