TreeView控件的一个简单问题?
我添加了一个treeview控件
控件已经安装了
引用也添加了
编译的时候也没有错误
但运行的时候浏览器左下方总有个脚本错误
treeview也没有显示,不知道是什么原因?
------解决方案--------------------下面的代码供参考,cs代码的两个方法可以合并到一个方法中:
aspx:
<%@ Register TagPrefix= "iewc " Namespace= "Microsoft.Web.UI.WebControls " Assembly= "Microsoft.Web.UI.WebControls " %>
<iewc:treeview id= "tv " runat= "server " SelectExpands= "True " ShowToolTip= "False " height= "300 " width= "400 "> </iewc:treeview>
aspx.cs
#region BindTree 绑定树
/// <summary>
/// 绑定树,项目信息
/// </summary>
/// <param name= "tnc "> </param>
/// <param name= "parentId "> </param>
/// <param name= "dt "> </param>
private void BindTree(TreeNodeCollection tnc, int intParentId, DataTable dt)
{
DataView dv = new DataView(dt);
dv.RowFilter = "PARENTID= " + intParentId;
dv.Sort = "PROJECTNAME ASC ";
// 如果有记录
if (dv.Count > 0)
{
TreeNode node;
// 遍历数据
foreach (DataRowView drv in dv)
{
node = new TreeNode();
node.ID = drv[0].ToString();
node.Text = drv[1].ToString();
node.Expandable = ExpandableValue.Auto;
this.BindTree(node.Nodes, Convert.ToInt32(node.ID), dt);
tnc.Add(node);
}
}
}
/// <summary>
/// 绑定树
/// </summary>
private void BindTree()
{
this.tvProject.Nodes.Clear();
//
TreeNode BaseNode = new TreeNode();
BaseNode.NodeData = this.PdbSession.curOneLevelID;
BaseNode.Text = this.PdbSession.curOneLevelName;
BaseNode.Expandable = ExpandableValue.Auto;
BaseNode.Expanded = true;
IPdbRptMainBLL MainBLL = new PdbRptMainBLLImp();
DataSet ds = MainBLL.GetProjectInfo();
//
DataView dv = new DataView(ds.Tables[ "PRODUCT "]);
dv.RowFilter = "ONELEVELNO= " + this.PdbSession.curOneLevelID;
dv.Sort = "PRODUCTNAME ASC ";
if (dv.Count > 0)
{
TreeNode node;
foreach (DataRowView drv in dv)
{
node = new TreeNode();
node.ID = drv[0].ToString();
node.Text = drv[1].ToString();
node.Expandable = ExpandableValue.Auto;
this.BindTree(node.Nodes, Convert.ToInt32(node.ID), ds.Tables[ "PROJECT "]);
BaseNode.Nodes.Add(node);
}
}
this.tvProject.Nodes.Add(BaseNode);
}
#endregion