求助,如果将我需要的数据绑定到TREEVIEW中
小弟用如下代码实现了整个数据表的绑定,可是我不想取出所有的分类,只想要我指定的,请问如何弄呢,谢谢,以下是代码,比方说我只要取出父ID为0,ID为2,3,4,5,6,7的分类及他们的子分类,子分类下的子分类。。。。。。。
请问如何来弄,谢谢
protected void Page_Load(object sender, EventArgs e)
{
string Sql = "select * from limfunction order by parentID ";
DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.sqlstring,CommandType.Text,Sql,null);
this.ViewState[ "ds "] = ds;
if (!this.IsPostBack)
{
AddTree(0, (TreeNode)null, TreeView0);
}
}
public void AddTree(int ParentID, TreeNode pNode,TreeView treename)
{
DataSet ds = (DataSet)this.ViewState[ "ds "];
DataView dvTree = new DataView(ds.Tables[0]);
//过滤ParentID,得到当前的所有子节点
dvTree.RowFilter = "[PARENTID] = " + ParentID ;
foreach (DataRowView Row in dvTree)
{
TreeNode Node = new TreeNode();
if (pNode == null)
{ //添加根节点
Node.Text = Row[ "cname "].ToString();
Node.Value = Row[ "ID "].ToString();
Node.NavigateUrl = Row[ "linkurl "].ToString();
Node.ToolTip = Row[ "cname "].ToString();
treename.Nodes.Add(Node);
Node.Expanded = true;
AddTree(Int32.Parse(Row[ "ID "].ToString()), Node,treename); //再次递归