Click here to Skip to main content
15,908,444 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
how to wrap the text in treeview in asp.net. i gave wrapnode =true in aspx page. but it is not working.
Posted
Comments
Naz_Firdouse 15-Jul-13 6:12am    
can you post your code???
christhuxavier 15-Jul-13 6:51am    
Hi naz, this is coding.

aspx;

<pre lang="xml"><asp:Content ID="fintree" runat="server" ContentPlaceHolderID="em">
<div style="overflow:scroll; width:200px; height:1000px;">
<asp:TreeView ID="ModuleTreeView" ExpandDepth="0" runat="server" ShowLines="true" PopulateNodesFromClient="True"
BackColor="#FFFFFF" style="width:300%" ForeColor="Black" HoverNodeStyle-ForeColor="BlueViolet"
ShowExpandCollapse="true" PopulateOnDemand="true" NodeWrap="true" >

</asp:TreeView>
</div></pre>





aspx.cs


namespace ShopGear1.View
{
public partial class treefin : System.Web.UI.Page
{
private string scon = "";

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
scon = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["sqlconnectstring"].ConnectionString;
//ModuleTreeView.CollapseAll();


FillTreeView();
}
}
public DataTable GetModuleDetails()
{
using (SqlConnection conn = new SqlConnection(scon))
{
string sql = ""query;
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
public void FillTreeView()
{

DataTable modules = new DataTable();
modules = GetModuleDetails();

ModuleTreeView.Nodes.Clear();

PopulateTreeNode(modules, null, 0);
}
private void PopulateTreeNode(DataTable modulelist, TreeNode parent, int parentid)
{
TreeNodeCollection baseNodes;
TreeNode node;
if (parent == null)
{
baseNodes = ModuleTreeView.Nodes;
}
else
{
baseNodes = parent.ChildNodes;
}
foreach (DataRow dtrow in modulelist.Rows)
{


if (int.Parse(dtrow["parent_orid"].ToString()) == parentid)
{
node = new TreeNode();

node.Text = dtrow["descript"].ToString();

node.Value = dtrow["code_webcategory_id"].ToString();
//string ID = node.Value.ToString().Trim();

node.SelectAction = TreeNodeSelectAction.Select;

node.ImageUrl = string.Format("~/View/iw.aspx?category={0}&width=50", node.Value);
baseNodes.Add(node);
PopulateTreeNode(modulelist, node, int.Parse(dtrow["code_webcategory_id"].ToString()));

}



}
//ModuleTreeView.CollapseAll();
}
}
}

1 solution

Hi naz, this is coding.

aspx;

XML
<asp:Content ID="fintree" runat="server" ContentPlaceHolderID="em">
    <div style="overflow:scroll; width:200px; height:1000px;">
    <asp:TreeView ID="ModuleTreeView" ExpandDepth="0" runat="server"  ShowLines="true" PopulateNodesFromClient="True"
 BackColor="#FFFFFF" style="width:300%"  ForeColor="Black" HoverNodeStyle-ForeColor="BlueViolet"
ShowExpandCollapse="true" PopulateOnDemand="true" NodeWrap="true" >

    </asp:TreeView>
    </div>






aspx.cs


namespace ShopGear1.View
{
public partial class treefin : System.Web.UI.Page
{
private string scon = "";

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
scon = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["sqlconnectstring"].ConnectionString;
//ModuleTreeView.CollapseAll();


FillTreeView();
}
}
public DataTable GetModuleDetails()
{
using (SqlConnection conn = new SqlConnection(scon))
{
string sql = ""query;
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
public void FillTreeView()
{

DataTable modules = new DataTable();
modules = GetModuleDetails();

ModuleTreeView.Nodes.Clear();

PopulateTreeNode(modules, null, 0);
}
private void PopulateTreeNode(DataTable modulelist, TreeNode parent, int parentid)
{
TreeNodeCollection baseNodes;
TreeNode node;
if (parent == null)
{
baseNodes = ModuleTreeView.Nodes;
}
else
{
baseNodes = parent.ChildNodes;
}
foreach (DataRow dtrow in modulelist.Rows)
{


if (int.Parse(dtrow["parent_orid"].ToString()) == parentid)
{
node = new TreeNode();

node.Text = dtrow["descript"].ToString();

node.Value = dtrow["code_webcategory_id"].ToString();
//string ID = node.Value.ToString().Trim();

node.SelectAction = TreeNodeSelectAction.Select;

node.ImageUrl = string.Format("~/View/iw.aspx?category={0}&width=50", node.Value);
baseNodes.Add(node);
PopulateTreeNode(modulelist, node, int.Parse(dtrow["code_webcategory_id"].ToString()));

}



}
//ModuleTreeView.CollapseAll();
}
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900