TreeView问题
在vs2003下没有问题,在vs2005下ID和Nodes怎么没有了
查了查可以用Tag代替ID可我这里还是没有呀!
private void InitTree(TreeNodeCollection Nds,string parenid)
{
DataView dv = new DataView();
TreeNode tmpNd;
string intID;
dv.Table = ds.Tables[ "tree "];
dv.RowFilter = "Parendid= " + parenid;
foreach (DataRowView drv in dv)
{
tmpNd = new TreeNode();
tmpNd.ID = drv[ "id "].ToString();
tmpNd.Text = drv[ "sortname "].ToString();
tmpNd.NavigateUrl = "NewsSortMenu.aspx?ver= " + me_ver + "&infoid= " + drv[ "id "].ToString();
Nds.Add(tmpNd);
intID = drv[ "ParedntId "].ToString();
InitTree(tmpNd.Nodes, tmpNd.ID);
}
}
[解决办法]
private void intiTree(TreeNodeCollection Nds, int parentId)
{
DataView dv = new DataView();
TreeNode tmpNd;
int strId;
dv.Table = objDataSet.Tables[ "TREE_INFO "];
dv.RowFilter = "PARENTID= ' " + parentId + " ' ";
foreach (DataRowView objRow in dv)
{
tmpNd = new TreeNode();
strId = (int)objRow[ "NODEID "];
tmpNd.Text = objRow[ "NODENAME "].ToString();
tmpNd.ImageUrl = objRow[ "Img "].ToString();
if (parentId == 0)
tmpNd.Expanded = true;
else
tmpNd.Expanded = false;
tmpNd.NavigateUrl = objRow[ "Adderss "].ToString();
Nds.Add(tmpNd);
intiTree(Nds[Nds.Count - 1].ChildNodes, strId);
}
}