yangl
yangl

Reputation: 337

Two questions of asp.net's treeview control

when i use tree view control,i find if it's node is too many,the treeview control will go beyond the table or page,How can i add a vertical scroll bar to treeview to avoid this?

this is my treeview 's layout:

                           <td>
                                   <asp:TreeView ID="TreeView1" OnSelectedNodeChanged="Select_Change"  runat="server" 
                                               Height="348px">
                                    <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
                                    <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" HorizontalPadding="0px"
                                    NodeSpacing="0px" VerticalPadding="0px" />
                                    <ParentNodeStyle Font-Bold="False" ImageUrl="~/images/bullet-red.png" />
                                    <RootNodeStyle ImageUrl="~/images/bullet.png" />
                                    <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px"
                                    VerticalPadding="0px" />

                                    </asp:TreeView>
                           </td>

another question is : i write this treeview's select change event like this:

    protected void Select_Change(Object sender, EventArgs e)
    {

        TextBox1.Text = "You selected: " + TreeView1.SelectedNode.Value;

    }

but when this event happen,the page always refresh,if i do not want to cause page refresh,how to do it?

Upvotes: 0

Views: 1239

Answers (2)

Emma
Emma

Reputation: 657

Answer to your Question1: How to add scroll bar to Treeview

 <div class="myTreeScroll">
     <%--Place Your Treeview in this div--%>
 </div>

Add This css,in your respective css file or in page:

.myTreeScroll {
width:300px;
height:200px;
overflow:auto;
border:1px solid #CCC; 
padding:5px 0;
position: relative;
}

Hope it helps you!

Upvotes: 1

Jason P
Jason P

Reputation: 27012

You can accomplish the scrolling by adding a css style of overflow:auto; or overflow:scroll; to the treeview's container element.

To prevent the page from reloading, you can either wrap the control in an UpdatePanel or use JavaScript and ajax instead of doing postbacks.

Upvotes: 0

Related Questions