Search code examples
asp.nettreeview

Align Checkbox in asp:TreeView


I have in my asp.net page asp:TreeView which generates checkboxes in codebehind.

<asp:TreeView  ID="TreeView1" Width="250px" NodeWrap="true" 
 ExpandDepth="1 ShowCheckBoxes="All" runat="server">
</asp:TreeView>

In the code behind elements and child elements are generated in this fashion inside a resultset loop.

 TreeNode tn1 = new TreeNode();

 TreeNode tn2 = new TreeNode();
 tn2.Text = "Child1";
 tn2.Value = "Child2";
 tn1.ChildNodes.Add(tn2);

However in the page the checkboxes are not aligned properly. I want to align them horizontally left. Any suggestions please.


Solution

  • Added a css class and now whitespaces are removed before the checkboxes and horizontal alignment is working properly.

    .tv table tbody tr 
    {  
        display: inline-block;  
        padding: 0px;
        margin-left :5px;
        width: 100%;  
    }
    
    <asp:TreeView ID="TreeView1" CssClass="tv" NodeIndent="2" NodeWrap="true" ExpandDepth="1" ShowCheckBoxes="All" runat="server">