what i think is u must first empty the childnodes added.
like
 t1.Nodes.Clear();
before binding  at selectionchanged event.

On Sat, Dec 13, 2008 at 11:36 PM, Abul Hasan Lakhani <
[email protected]> wrote:

> I have TreeView in one UpdatePanel 'upTreeView' which uses TreeNodePopulate
> to populate the Tree. When I select any node in the TreeView it should
> display information about that node in the DetailsView... which is in
> another UpdatePanel 'upDetails'
>
> This works very well without using update panels. but when I implement the
> AJAX Update Panels.Its not functioning very well and all sorts of unusual
> behavior starts to happen.
>
> Firstly, It works well if I only expand or collapse the nodes without
> selecting any node. the problem starts when I click few nodes....
>
> 1- Duplicating Nodes..
>
> 2- Expanding other nodes... which i have not selected or expanded..
>
> You are free to have a look at it as a live demo... you will find
> the problem by yourself... 
> *http://www.ecsonline.com.pk*<http://www.ecsonline.com.pk/> &
> without Ajax Site ( <http://www.ecsonline.com.pk/>*
> http://www.ecsonline.com.pk*<http://www.ecsonline.com.pk/withoutAjax/Default.aspx>
> */withoutAjax/Default.aspx*)* *
>
>  I want to get this thing done.. I this is an ongoing project.. and the
> client is asking for ajax functionality ( Frames like functionality ). I am
> using Access Database on backend.
>
> BusinessLayer.cs
> public static TreeView PopulateRootLevel ( TreeView tv )
>
> {
>
> //OleDbConnection objConn = new
> OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
>
> // Request.MapPath("App_Data/sdsAccounts.mdb") + ";Persist Security
> Info=False");using (OleDbConnection objConn = ConnectionsManager.GetConnection
> ())
>
> {
> OleDbCommand objCommand = new OleDbCommand (@"select
> acc_code,acc_title,(select count(*) FROM ChartOfAccounts WHERE
> acc_parent=coa.acc_code) AS childnodecount FROM ChartOfAccounts coa where
> acc_parent IS NULL ORDER BY acc_Code", objConn);
>
> //OleDbCommand objCommand = new OleDbCommand (@"select
> acc_code,acc_title,(select count(*) FROM ChartOfAccounts WHERE
> acc_parent=coa.acc_code) AS childnodecount,acc_Parent FROM ChartOfAccounts
> coa where acc_parent IS NULL ORDER BY acc_Code", objConn);OleDbDataAdapterda =
> new OleDbDataAdapter (objCommand);DataTable dt = new DataTable ();
>
> da.Fill (dt);
>
> PopulateNodes (dt, tv.Nodes);
> return tv;
>
> }
>
> }
> public static TreeNode PopulateSubLevel ( string parent, TreeNode ND )
>
> {
> using (OleDbConnection objConn = ConnectionsManager.GetConnection ())
>
> {
> OleDbCommand objCommand = new OleDbCommand (@"select
> acc_code,acc_title,(select count(*) FROM " +
>
> "ChartOfAccounts WHERE acc_parent=coa.acc_code) AS childnodecount FROM " 
> +"ChartOfAccounts
> coa where acc_pare...@parentid ORDER BY acc_Code", objConn);
>
> objCommand.Parameters.Add (
> "@parentID", OleDbType.VarChar).Value = parent;OleDbDataAdapter da = new
> OleDbDataAdapter (objCommand);DataTable dt = new DataTable ();
>
> da.Fill (dt);
>
> PopulateNodes (dt, ND.ChildNodes);
> return ND;
>
> }
>
> }
> private static void PopulateNodes ( DataTable dt, TreeNodeCollection nodes
> )
>
> {
> foreach (DataRow dr in dt.Rows)
>
> {
> TreeNode tn = new TreeNode ();
>
> tn.Text = dr[
> "acc_title"].ToString ();tn.Value = dr["acc_code"].ToString ();
>
> nodes.Add (tn);
>
> //If node has child nodes, then enable on-demand populatingtn.PopulateOnDemand
> = ((int)(dr["childnodecount"]) > 0);
>
> }
>
> }
>
> *Default.aspx (Markup)*
>
> *UpdatePanel 1*
>
> <asp:UpdatePanel ID="upTreeView" runat="server" ChildrenAsTriggers="False"
> UpdateMode="Conditional">
>
> <ContentTemplate>
>
> <asp:TreeView ID="TreeView1" runat="server" ImageSet="Msdn" NodeWrap
> ="True" LineImagesFolder="~/TreeImages" BackColor="#DEE8F5" ExpandDepth
> ="0" NodeIndent="10" ShowLines="True" Width="331px" OnTreeNodePopulate
> ="TreeView1_TreeNodePopulate">
>
> . . .
>
> </asp:TreeView>
>
> </ContentTemplate>
>
> <Triggers>
>
> <asp:AsyncPostBackTrigger ControlID="TreeView1" EventName
> ="TreeNodePopulate" />
>
> </Triggers>
>
> </asp:UpdatePanel>
>
> *UpdatePanel 2*
>
> <asp:UpdatePanel ID="upDetails" runat="server">
>
> <ContentTemplate>
>
> <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
> CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333"
> GridLines="None" OnDataBound="DetailsView1_DataBound" OnItemUpdated
> ="DetailsView1_ItemUpdated" OnItemDeleted="DetailsView1_ItemDeleted"
> OnItemInserted="DetailsView1_ItemInserted" DataKeyNames="acc_Code"
> OnModeChanged="DetailsView1_ModeChanged" Width="387px" BorderColor="Black"
> BorderStyle="Solid" BorderWidth="1px" EmptyDataText="Select Account from
> the left menu" OnItemCommand="DetailsView1_ItemCommand">
>
> . . . .
>
> <Fields>
>
> . . . . .
>
> </Fields>
>
> . . . . .
>
> </asp:DetailsView>
>
> <asp:Label ID="Label7" runat="server" Font-Bold="True" ForeColor="Red"
>
> Width="134px" Visible="False"></asp:Label>
>
> </ContentTemplate>
>
> <Triggers>
>
> <asp:AsyncPostBackTrigger ControlID="TreeView1" EventName
> ="SelectedNodeChanged" />
>
> </Triggers>
>
> </asp:UpdatePanel>
>
> *Default.aspx.cs*
>
> protected void TreeView1_TreeNodePopulate ( object sender, TreeNodeEventArgs 
> e )
>
>
>
>
>
> {
> BusinessLayer.PopulateSubLevel (e.Node.Value, e.Node);
>
> }
>
>
> I have heard that its not a better solution.. to put treeview in
> updatepanels... what is the more appropriate solution??
>
> Regards,
>
> Abul Hasan Lakhani.
>
>
> --
> Abul Hasan Lakhani
>

Reply via email to