Abbas
Abbas

Reputation: 5044

Working with checkbox in treeview asp.net

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.

Upvotes: 3

Views: 24218

Answers (3)

Agamand The True
Agamand The True

Reputation: 832

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.

Upvotes: 2

James Johnson
James Johnson

Reputation: 46047

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>

Upvotes: 1

rick schott
rick schott

Reputation: 20617

Here is a nice walk-though:

ASP.NET TreeView and Checkboxes

Upvotes: 1

Related Questions