Click here to Skip to main content
11,480,532 members (50,431 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 C#3.0 C# C#4.0 C#3.5 C#5
Suppose that we have treeview with checkbox including node1 and sub node 1.1,1.2,1.3,1.4.
i want to do this that when a user select all of the sub nodes the main node selected automatically and if user select some of the sub nodes the main node selected in other way.like a filled square.
how can i do this??????
Posted 24-Jul-11 23:14pm
Comments
keerth516 at 4-Jul-14 2:57am
   
I have done the same process in WPF.do you require any help please let me know.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

sir, you need to loop through every node and check if all the childs are selected and if yes you need to programitically check the parent true.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Hi,

I think this is the default functionality present in Telerik RadTreeView.
http://demos.telerik.com/aspnet-ajax/treeview/examples/overview/defaultcs.aspx[^]

It may also be present in asp TreeView. Try and search and you will know.

Regards,
Praneet
  Permalink  
Comments
CHill(Hawkeye)60 at 8-May-14 7:08am
   
The question is nearly 3 years old !! (Nor did the OP mention ASP.net)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Desing code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
 
        function postBackByObject() {
            var o = window.event.srcElement;
            if (o.tagName == "INPUT" && o.type == "checkbox") {
                __doPostBack("", "");
            }
        }
   </script>
 

</head>
<body>
    <form id="form1" runat="server">
    <div>
 
        <asp:TreeView ID="TreeView1" runat="server" ShowCheckBoxes="All"
 
            AutoGenerateDataBindings="False" ExpandDepth="0"
               EnableClientScript="true"
            ontreenodepopulate="TreeView1_TreeNodePopulate"
            ontreenodecheckchanged="TreeView1_TreeNodeCheckChanged"
            onselectednodechanged="TreeView1_SelectedNodeChanged" >
 
        </asp:TreeView>
 

     <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
 

 

    </div>
    </form>
</body>
</html>


Cs code :



public partial class Default2 : System.Web.UI.Page
{
    DataTable dt = new DataTable();
    private SqlConnection con;
    protected void Page_Load(object sender, EventArgs e)
    {
            TreeView1.Attributes.Add("onclick", "postBackByObject()");
 
            if (!IsPostBack)
            {
                string cs = "server=sql2005 ;database=dbName; uid=sa;pwd=123";
                con = new SqlConnection(cs);
                con.Open();
                SqlCommand cme = new SqlCommand("select * from tbName where parenttab=0 and roleid=1", con);
                //cme.CommandType = CommandType.StoredProcedure;

                SqlDataAdapter da = new SqlDataAdapter(cme);
                DataSet ds = new DataSet();
                da.Fill(ds, "T");
 
                dt = ds.Tables["T"];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    TreeNode no = new TreeNode();
                    no.Text = dt.Rows[i]["LinkName"].ToString();
                    // no.SelectAction = TreeNodeSelectAction.SelectExpand;

                    no.Value = dt.Rows[i]["LinkId"].ToString();
                    int a = Convert.ToInt32(dt.Rows[i]["LinkId"]);
 
                    // int a = Convert.ToInt32(dt.Rows[i]["LinkId"]);
                    AddTrem(no,a);
                    this.TreeView1.Nodes.Add(no);
 
                }
            }
    }
 
    public void AddTrem(TreeNode no,int a)
    {
 
        SqlCommand cme = new SqlCommand("select * from tbName where parenttab="+a, con);
        SqlDataAdapter da = new SqlDataAdapter(cme);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataTable dt = new DataTable();
        dt = ds.Tables[0];
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            TreeNode childnode = new TreeNode();
            childnode.Text = dt.Rows[i]["LinkName"].ToString();
            childnode.Value = dt.Rows[i]["linkid"].ToString();
           // AddSubject(childnode);
            no.ChildNodes.Add(childnode);
        }
    }
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

May this help you.

[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 215
1 Richard MacCutchan 150
2 CHill60 90
3 CPallini 70
4 Dave Kreskowiak 70
0 Sergey Alexandrovich Kryukov 7,874
1 OriginalGriff 7,556
2 Sascha Lefèvre 3,074
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 18 Jul 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100