Gitz
Gitz

Reputation: 820

Checked Change event of tree view is not working

I am working with Treeview control and I am using the following code

  <asp:TreeView ID="tvCategories" ShowCheckBox="False" Style="font-family: Trebuchet MS;
                                    margin-top: 5px; margin-bottom: 5px; margin-left: 20px; color: Black; font-size: 12px"
                                    runat="server" ShowLines="true" NodeIndent="5" OnTreeNodeCheckChanged="tvCategories_TreeNodeCheckChanged"
                                    OnSelectedNodeChanged="tvCategories_SelectedNodeChanged">
                                    <LeafNodeStyle ForeColor="#555555" />
                                    <ParentNodeStyle ForeColor="Black" />
                                    <RootNodeStyle ForeColor="Black" />
                                </asp:TreeView>

Both the OnTreeNodeCheckChanged and OnSelectedNodeChanged are not working and the AutoPostBack property is not available for Treeview.

Please help me out with this issue. Thanks

Upvotes: 5

Views: 4323

Answers (2)

Neel
Neel

Reputation: 11741

You need use javascript to make the page postback, then the treenodecheckchanged event can be fired.

like below, you should add the code of bolder to make the page postback.:

 <script language="javascript" type="text/javascript">
     function postBack()
 {
     var element = window.event.srcElement;
     if (element .tagName == "INPUT" && element.type == "checkbox")
     {
        __doPostBack("","");
     } 
 }

</script>

Add the above javascript code in the head section of the page.

onclick="javascript:postBack()"  

Upvotes: 5

Vishal Suthar
Vishal Suthar

Reputation: 17194

There is no AutoPostBack property for TreeView.

As per the MSDN:

The TreeNodeCheckChanged event is raised when a check box in the TreeView control changes state between posts to the server. This allows you to provide an event-handling method that performs a custom routine, such as updating a database or the displayed content, whenever this event occurs.

You can try javascript to postback the page by adding the onclick event.

Reference: PostBack on selecting checkbox of treeview

Upvotes: 4

Related Questions