3

i want to know how to program the checkbox checked inside treeview, i want to write code when user checks checkbox inside the treeview in asp.net, i got the event known as TreeNodeCheckChange event, i wrote a response.write() message inside it, but when i check the checkbox, nothing happens, does the asp.net treeview supports handling the checkbox from code behind.

Thanks in advance.

3 Answers 3

2

When u click on the check box the postback event won't fire, this is ootb settings. You have to check the checkbox first and then click on the checkbox title. Only then the postback event will fire. Then in the code behind you can access the checkbox node properties using this :-

protected void someTree_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
{
    if (e.Node.Checked)
    {
    }
}

The other workaround (the more user friendly way) is to fire the postback immediately when the checkbox is checked. In order to do that you can follow this tutorial here:- http://www.keirgordon.com/post/PostBack-on-TreeView-Checkbox-Click.aspx

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

1

Try setting SelectAction="Select" on the TreeNode element.

<asp:TreeView ID="TreeView1" runat="server" OnTreeNodeCheckChanged="TreeView1_TreeNodeCheckChanged">
    <Nodes>
        <asp:TreeNode ShowCheckBox="true" SelectAction="Select" />
    </Nodes>
</asp:TreeView>

2 Comments

i added the pNode.SelectAction = TreeNodeSelectAction.Select but still i cannot see anything when i click on any of the checkbox, i am using OnTreeNodeCheckChanged event also, and have a response.write message inside it
Are you using AJAX? Is the TreeView in an UpdatePanel? If so, Response.Write will not work.
1

Here is a nice walk-though:

ASP.NET TreeView and Checkboxes

1 Comment

i want to handle it from code behind and not from javascript, as i am not too good in javascript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.