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();
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.
Hi,
I chanced upon your code whilst looking for solutions to bind an ultrawebtree to a dataset.
My situation is very similar to your example and I have the ultrawebtree successfully binding, however, when the nodebound event fires, the Node.DataItem is nothing.
Could you give me an insight on how to resolve this issue?
Thanks
halo thomas,
i am having the same problems too, i think it is regarding to the versions, when i'm using 7.2 DataItem is null but when i'm trying to use 8.2 it working just fine
Hello Thomas,
I just want to officially confirm that, this is an issue that has been addressed in 8.2. There is a superb thread with info on the fix and great code sampless here:
http://forums.infragistics.com/forums/p/11959/45030.aspx#45030