Loading ...

Asp.net Treeview data binding update problem??

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  getting started / general asp.net   » Asp.net Treeview data binding update problem??

Asp.net Treeview data binding update problem??

Posts under the topic: Asp.net Treeview data binding update problem??

Posted: 12/1/2010

Starter 1414  points  Starter
  • Joined on: 12/1/2008
  • Posts: 66

Hi,

I am working on an asp.net web application that uses treeview control to
display hierarchical data from an xml data source. When I changed the xml
data source the treeview doesn't update itself. The treeview data source is
asp XMLDataSource that is transformed by an xlst file. The xml data is
generated from SQL database and dynamically bind to the XmlDataSource. Is it
possible to use this method to bind data to treeview control?

 

Thanks,

Sumit Arora


Posted: 12/1/2010

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

Please explain your issue with relevant code.


Posted: 12/1/2010

Starter 1414  points  Starter
  • Joined on: 12/1/2008
  • Posts: 66

The problem which I'm having is I'm using asp.net treeview control. And there is a button on the same page where I add a new node to a tree. When the page postbacks it doesn't show the new node which I added in the treeview.

I'm binding the treeview like this:

Test test=new Test(); 
test.ID= Convert.ToInt32(Request.QueryString["Id"].Trim());
  DataSet ds= TestBLL.GetOrganizationTreeByID(test.ID);
 if (ds.Tables[0].Rows.Count > 0)
  {
          foreach (DataRow dr1 in DsTree.Tables[0].Rows)
          {
                 if (dr1["parentid"] == DBNull.Value)
                  {
                      dr1["parentid"] = "0";
                  }
           }
           DataRow dr = ds.Tables[0].NewRow();
            dr["UnitID"] = "0";
            dr["OfficeID"] = ds.Tables[0].Rows[0]["OfficeID"].ToString();
            dr["UnitName"] = ds.Tables[0].Rows[0]["OfficeName"].ToString();
            dr["ParentID"] =DBNull.Value;
            dr["Rank"] = "0";
            ds.Tables[0].Rows.InsertAt(dr, 0);
            ds.AcceptChanges();
            ds.DataSetName = "Menus";
            ds.Tables[0].TableName = "Menu";
            DataRelation relation = new DataRelation("ParentChild",
                                DsTree.Tables["Menu"].Columns["UnitID"],
                                DsTree.Tables["Menu"].Columns["ParentID"],
                                true);
            relation.Nested = true;
            ds.Relations.Add(relation);
            xmlDataSource.Data = ds.GetXml();
            trTreeView.Visible = true;
 } 


Mark up looks like this:

 

<asp:TreeView ID="treeView" runat="server" ShowCheckBoxes="All" ForeColor="#990000" AutoGenerateDataBindings="False" 
style="margin-right: 0px" TabIndex="2" 
ontreenodedatabound="Menu1_TreeNodeDataBound"  
DataSourceID="xmlDataSource" ShowLines="True" 
ontreenodecheckchanged="Menu1_TreeNodeCheckChanged">
<DataBindings>
<asp:TreeNodeBinding DataMember="MenuItem"   NavigateUrlField="NavigateUrl" TextField="UnitName" ToolTipField="ToolTip" TargetField="Rank" ValueField="Value" />
</DataBindings>
</asp:TreeView>   


<asp:XmlDataSource ID="xmlDataSource" TransformFile="~/XSLT.xsl" XPath="MenuItems/MenuItem" runat="server" />


Now when I add a new node in on button click event. And calling the method that excutes the above code. It doesn't show the new item that being added.

 I hope you would be able to understand now what I want to do exactly.

Thanks,

Sumit Arora

 


Posted: 12/1/2010

Starter 1414  points  Starter
  • Joined on: 12/1/2008
  • Posts: 66
  Answered

Found the mystery behind the problem....just need to set the EnableCahing="false" in XmlDataSource control.

 

 

<asp:XmlDataSource ID="xmlDataSource" EnableCaching="false" TransformFile="~/TransformXSLT.xsl" XPath="MenuItems/MenuItem" runat="server"/>

 


Page 1 of 1 (4 items)