You must Sign In to post a response.
  • Category: .NET

    checkboxes in treeview

    The forum thread has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this thread.
    This thread will be reviewed shortly.
    If you think this thread contain inappropriate content, please report to webmaster.

    i have a dynamically generated treeview,which shows all the available books in a library.

    here different categories r parent nodes n books available in that particular category are child nodes.

    for selecting books,i want to add check boxes,only for child nodes ( not for category)

    if i select the 'checkbox' option,then i'll get check boxes even for parent nodes.

    any other suggestions/options for selecting books(child nodes)-(max of 4-books allowed)
    it should all the user to select 'n' books(here its 4)

    thanx in advance,
  • #472
    I believe there is a checkbox option even at the Node level. You could use that.

  • #1949

    Try this method of coding.Since u bind data dynamically,u can allow checkbox only to nodes as follows.To get immediate action for the check of each checkbox set autopostback property of treeview to true.If u use separate button for the validation of
    checks no need of setting autopostback property.

    Dim newNode1 As TreeNode = New TreeNode()
    newNode1.Text = "hello"
    Dim newNode3 As TreeNode = New TreeNode()
    newNode3.Text = "hai"
    newNode3.CheckBox = True


  • #219202
    TreeView Declaration

    <asp:TreeView ID="TreeView1" Runat="server" DataSourceID="XmlDataSource1" onclick="client_OnTreeNodeChecked();" ShowCheckBoxes="all">


    <asp:TreeNodeBinding DataMember="Category" ValueField="ID" TextField="Name"></asp:TreeNodeBinding>

    <asp:TreeNodeBinding DataMember="Description" ValueField="Value" TextField="Value"></asp:TreeNodeBinding>



    The Javascript Code snippet is as follows:-

    <script language="javascript" type="text/javascript">
    function client_OnTreeNodeChecked()
    var obj = window.event.srcElement;
    var treeNodeFound = false;
    var checkedState;
    if (obj.tagName == "INPUT" && obj.type == "checkbox") {
    var treeNode = obj;
    checkedState = treeNode.checked;
    obj = obj.parentElement;
    } while (obj.tagName != "TABLE")
    var parentTreeLevel = obj.rows[0].cells.length;
    var parentTreeNode = obj.rows[0].cells[0];
    var tables = obj.parentElement.getElementsByTagName("TABLE");
    var numTables = tables.length
    if (numTables >= 1)
    for (i=0; i < numTables; i++)
    if (tables[i] == obj)
    treeNodeFound = true;
    if (i == numTables)
    if (treeNodeFound == true)
    var childTreeLevel = tables[i].rows[0].cells.length;
    if (childTreeLevel > parentTreeLevel)
    var cell = tables[i].rows[0].cells[childTreeLevel - 1];
    var inputs = cell.getElementsByTagName("INPUT");
    inputs[0].checked = checkedState;

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.