看看我的代码~~
if(!Page.IsPostBack)
{
SqlConnection CN = new SqlConnection(ConfigurationSettings.AppSettings["SQLConnectionString"]);
try
{
SqlDataAdapter adp = new SqlDataAdapter("select CategoryId,Description,ParentCategotyId from Categories",CN);
DataSet ds=new DataSet();
adp.Fill(ds);
this.ViewState["ds"]=ds;
}
catch (Exception ex)
{
Session["Error"] = ex.ToString();
Response.Redirect("error.aspx"); //?跳转程序的公共错误处理页面
}
finally
{
CN.Close();
}
//调用递归函数,完成树形结构的生成
AddTree(0, (TreeNode)null);
}public void AddTree(int ParentCategotyId,TreeNode pNode) //ParentID
{
DataSet ds=(DataSet) this.ViewState["ds"];
DataView dvTree = new DataView(ds.Tables[0]);
//过滤ParentID,得到当前的所有子节点
dvTree.RowFilter = "[ParentCategotyId] = " + ParentCategotyId;
foreach(DataRowView Row in dvTree)
{
TreeNode Node=new TreeNode() ;
if(pNode == null)
{ //添加根节点
Node.Text = Row["Description"].ToString();//ConText
TreeView1.Nodes.Add(Node);
Node.Expanded=true;
AddTree(Int32.Parse(Row["CategoryId"].ToString()), Node); //再次递归 ID
}
else
{ //?添加当前节点的子节点
Node.Text = Row["Description"].ToString();
pNode.Nodes.Add(Node);
Node.Expanded = true;
AddTree(Int32.Parse(Row["CategoryId"].ToString()),Node); //再次递归
}
}
}谁知道treeview加载时默认不要展开根节点??只有父节点,而没有根节点和子节点?点击父节点才展开!!
if(!Page.IsPostBack)
{
SqlConnection CN = new SqlConnection(ConfigurationSettings.AppSettings["SQLConnectionString"]);
try
{
SqlDataAdapter adp = new SqlDataAdapter("select CategoryId,Description,ParentCategotyId from Categories",CN);
DataSet ds=new DataSet();
adp.Fill(ds);
this.ViewState["ds"]=ds;
}
catch (Exception ex)
{
Session["Error"] = ex.ToString();
Response.Redirect("error.aspx"); //?跳转程序的公共错误处理页面
}
finally
{
CN.Close();
}
//调用递归函数,完成树形结构的生成
AddTree(0, (TreeNode)null);
}public void AddTree(int ParentCategotyId,TreeNode pNode) //ParentID
{
DataSet ds=(DataSet) this.ViewState["ds"];
DataView dvTree = new DataView(ds.Tables[0]);
//过滤ParentID,得到当前的所有子节点
dvTree.RowFilter = "[ParentCategotyId] = " + ParentCategotyId;
foreach(DataRowView Row in dvTree)
{
TreeNode Node=new TreeNode() ;
if(pNode == null)
{ //添加根节点
Node.Text = Row["Description"].ToString();//ConText
TreeView1.Nodes.Add(Node);
Node.Expanded=true;
AddTree(Int32.Parse(Row["CategoryId"].ToString()), Node); //再次递归 ID
}
else
{ //?添加当前节点的子节点
Node.Text = Row["Description"].ToString();
pNode.Nodes.Add(Node);
Node.Expanded = true;
AddTree(Int32.Parse(Row["CategoryId"].ToString()),Node); //再次递归
}
}
}谁知道treeview加载时默认不要展开根节点??只有父节点,而没有根节点和子节点?点击父节点才展开!!
解决方案 »
- discuz nt整合
- 不能退出系统
- 关于gnome源码下载方式,请教
- 一个6X6二维数组 的运算
- 怎么使用__doPostBack,我的有问题啊
- 使用了Netadvantage 控件和AspNetPager 控件的页面发布到空间上就出错?
- 服务器控件button的onclick属性和button_click事件的区别
- Gridview 嵌入 Panel 内,实现纵向滚动,但 Gridview 的列标头也滚动,怎样不滚动?
- 小问题,大分数(100分,解决马上结!)
- .net 服务器执行bat
- 求一正规则的小问题。。。。。。。。。。。。。。。。。。。。谢谢了。。
- 请问Replace(chr(13),"<br>");这个在asp的表达式在asp.net中应该怎么写
或
Node.ExpandLevel = 0;