hi..
i have a treeview which consists on static parent and child node that can never change,
now i want to save these nodes I mean child nodes in db those node which are checked.
how it is possible?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Deepak SharmaPosted Jan 31, 2012, 11:31 PM
Declare a static variable:
public static List
Initialize it :
treeList = new List
In the TreeView BeforeCheck event write :
private void treeView1_BeforeCheck(object sender, TreeViewCancelEventArgs e)
{
// If node is not checked, it is checked and added to the static TreeNode List 'treeNodeList'
if (!e.Node.Checked)
{
treeNodeList.Add(e.Node);
}
else
// If node is checked, it is unchecked and removed from the static TreeNode List 'treeNodeList'
{
treeNodeList.Remove(e.Node);
}
}
Write insert code in a Button click event or any other place :
private void button1_Click(object sender, EventArgs e)
{
foreach (TreeNode node in treeList)
{
// write your insert code here
MessageBox.Show(node.Text);
}
}
Kanhialal kkPosted Jan 31, 2012, 6:55 AM
Deepak SharmaPosted Jan 27, 2012, 1:55 AM
you can write following code to insert checked nodes to db :
foreach (TreeNode node in TreeView1.CheckedNodes)
{
// write your insert code here
Response.Write(node.Text + " ");
}