.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

treeview in asp.net

Posted By: Dom     Posted Date: February 15, 2010    Points:2   Category :ASP.Net
Im using treeview in asp.net...in my pageload event(!page.ispostback) i declare

treeview.collapsall(); method in which on first time loading all nodes are collapsed when i expand one parent node and if i select any child node then all nodes collapsed again...i need the current node position when page is refreshed how?

Responses
Author: Lalij Mer             
Posted Date: February 15, 2010     Points: 5   
Author: TotalDotNet             
Posted Date: August 16, 2010     Points: 5   

try using following code
or go through example and demo in
http://www.totaldotnet.com/NavigationControls/Asp_TreeViewControl.aspx

Code Behind

protected void TreeView2_DataBound(object sender, EventArgs e)
{
TreeView2.ExpandAll();
}

protected void Button1_Click(object sender, EventArgs e)
{

TreeView2.FindNode("Types/sbyte").Collapse();
}

protected void Button2_Click(object sender, EventArgs e)
{
TreeNode tnode = new TreeNode();
tnode.Text = "mhar";
tnode.Value = "128";
tnode.NavigateUrl = "";
tnode.SelectAction = TreeNodeSelectAction.None;
tnode.ChildNodes.Add(new TreeNode()
{
Text = "Range:128",
Value = "128"
});
tnode.ChildNodes.Add(new TreeNode()
{
Text = "Size:Unsigned 8-bit integer",
Value = "8 bit"
});
TreeView2.FindNode("Types").ChildNodes.Add(tnode);

}


Aspx Page(using .sitemap file)

<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Collapse" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Add" OnClick="Button2_Click" />
<asp:SiteMapPath ID="SiteMapPath2" runat="server">
</asp:SiteMapPath>
<em>
<asp:TreeView ID="TreeView2" runat="server" OnDataBound="TreeView1_DataBound" DataSourceID="SiteMapDataSource1"
ImageSet="Simple" NodeIndent="10">
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="#DD5555" />
<SelectedNodeStyle Font-Underline="True" ForeColor="#DD5555" HorizontalPadding="0px"
VerticalPadding="0px" />
<NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="0px"
NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>
</em>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
</form>



Author: TotalDotNet             
Posted Date: August 16, 2010     Points: 5   

try using following code
or go through example and demo in
http://www.totaldotnet.com/NavigationControls/Asp_TreeViewControl.aspx

Code Behind

protected void TreeView2_DataBound(object sender, EventArgs e)
{
TreeView2.ExpandAll();
}

protected void Button1_Click(object sender, EventArgs e)
{

TreeView2.FindNode("Types/sbyte").Collapse();
}

protected void Button2_Click(object sender, EventArgs e)
{
TreeNode tnode = new TreeNode();
tnode.Text = "mhar";
tnode.Value = "128";
tnode.NavigateUrl = "";
tnode.SelectAction = TreeNodeSelectAction.None;
tnode.ChildNodes.Add(new TreeNode()
{
Text = "Range:128",
Value = "128"
});
tnode.ChildNodes.Add(new TreeNode()
{
Text = "Size:Unsigned 8-bit integer",
Value = "8 bit"
});
TreeView2.FindNode("Types").ChildNodes.Add(tnode);

}


Aspx Page(using .sitemap file)

<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Collapse" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Add" OnClick="Button2_Click" />
<asp:SiteMapPath ID="SiteMapPath2" runat="server">
</asp:SiteMapPath>
<em>
<asp:TreeView ID="TreeView2" runat="server" OnDataBound="TreeView1_DataBound" DataSourceID="SiteMapDataSource1"
ImageSet="Simple" NodeIndent="10">
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="#DD5555" />
<SelectedNodeStyle Font-Underline="True" ForeColor="#DD5555" HorizontalPadding="0px"
VerticalPadding="0px" />
<NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="0px"
NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>
</em>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
</form>





Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend