Reputation: 5044
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
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
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