Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
55
Pre-populate which nodes are checked on Bind/PreRender
posted

I use a WebTree control to have a user enter information into a database, but have to give him the ability to edit and update the same entry later. For this, I need to populate the tree with the same nodes checked as when the information was initially submitted.

I return a DataSet with the checked  DataKey values (a Unique ID in the Database), so as each node is created, I can check it's LevelKeyField value and match the ones which needs to be rendered as checked, but how and where?

Here is the basic outline of my TreeView Population method:

//Get a DataAdapter
            SqlDataAdapter da = (SqlDataAdapter)GetTreeViewData(Status);
      
            //Create a DataSet and fill the dataset
            DataSet ds = new DataSet("aacacacacac");
            da.Fill(ds, "aacacacacac");

            try
            {
                // Set up Relationships
                ds.Relations.Add("aaaaaa", ds.Tables["acacacac"].Columns["UniqueID"],ds.Tables["acacacac"].Columns["UniqueID"]);
            }
            catch (Exception x)
            {
                string s = x.Message;
                this.lblErrorMessage.Text = x.Message;
            }
        //Set TreeView Settings

        this.tvRecipients.LoadOnDemandPrompt = "<em>loading collectors</em>";
        this.tvRecipients.DataKeyOnClient = true;
        this.tvRecipients.DataSource = ds.Tables["XXXXXXXX"].DefaultView;
        this.tvRecipients.Levels[0].LevelKeyField = "UniqueID";
        this.tvRecipients.Levels[0].RelationName = "ccccccc";
        this.tvRecipients.Levels[0].ColumnName = "dddddddd";
        this.tvRecipients.Levels[1].ColumnName = "rrrrrrrrr";
        this.tvRecipients.Levels[1].LevelKeyField = "UniqueID";
        this.tvRecipients.DataBind();

Parents
No Data
Reply
  • 28464
    Verified Answer
    posted

    I believe what you are looking for is the NodeBound event. In NodeBound, you can get to the item being currently bound to the current node and map datasource item fields to node properties. In the sample below, I am mapping the IsChecked boolean column to the Checked property of the node

             
        <ignav:UltraWebTree ID="UltraWebTree1" runat="server" CheckBoxes="true"
                onnodebound="UltraWebTree1_NodeBound">
        </ignav:UltraWebTree>
        
        
        protected void Page_Load(object sender, EventArgs e)
        {
            DataSet dataSet = new DataSet();

            DataTable orders = new DataTable();
            orders.TableName = "Orders";
            orders.Columns.Add("ID");
            orders.Columns.Add("Name");
            orders.Columns.Add("IsChecked");

            orders.Rows.Add(new object[ { 1, "Nike shoes", true });
            orders.Rows.Add(new object[ { 2, "Adidas shoes", false });
            orders.Rows.Add(new object[ { 3, "Puma shoes", false });

            DataTable details = new DataTable();
            details.Columns.Add("ID");
            details.Columns.Add("ParentID");
            details.Columns.Add("Name");
            details.Columns.Add("IsChecked");

            details.Rows.Add(new object[ { 1, 1, "Air Jordan", true });
            details.Rows.Add(new object[ { 2, 2, "Kevin Garnett", false });
            details.Rows.Add(new object[ { 3, 3, "Brazil Football", false });

            dataSet.Tables.Add(orders);
            dataSet.Tables.Add(details);       
            

            dataSet.Relations.Add("OrderDetails", orders.Columns["ID"], details.Columns["ParentID"]);        

            UltraWebTree1.Levels[0].RelationName = "OrderDetails";
            UltraWebTree1.Levels[0].ColumnName = "Name";
            UltraWebTree1.Levels[1].ColumnName = "Name";

            UltraWebTree1.DataSource = dataSet.Tables[0].DefaultView;
            UltraWebTree1.DataBind();  
        }

        protected void UltraWebTree1_NodeBound(object sender, Infragistics.WebUI.UltraWebNavigator.WebTreeNodeEventArgs e)
        {
            DataRow dataRow = e.Node.DataItem as DataRow;
            if (Convert.ToBoolean(dataRow["IsChecked"]))
            {
                e.Node.Checked = true;
            }
        }

    Hope this helps. 

Children