private void getTreeView()
{
DataSet ds = new DataSet();
categoryController = new CategoryController();
ds = categoryController.GetDataExecStoreProc("cadGetCategoryLevel @PARENTID =0"); //stored procedure
categoryTreeView.Nodes.Clear();
int currLevel = 1;
int maxLevel = Int32.Parse(ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["level"].ToString());
Hashtable listNode = new Hashtable();
Hashtable tmplistNode = new Hashtable();
DataRow[] levelsub;
while (currLevel <= maxLevel)
{
listNode = (Hashtable)tmplistNode.Clone();
tmplistNode.Clear();
levelsub = ds.Tables[0].Select("level = " + currLevel.ToString());
foreach (DataRow dbRow in levelsub)
{
string parentid = dbRow["ParentID"].ToString();
int catid = Convert.ToInt32(dbRow["CategoryID"].ToString());
TreeNode newNode = CreateNode(dbRow["CategoryName"].ToString(), dbRow["CategoryID"].ToString(), false);
if (currLevel == 1)
{
categoryTreeView.Nodes.Add(newNode);
}
else
((TreeNode)listNode[parentid]).ChildNodes.Add(newNode);
tmplistNode.Add(newNode.Value.ToString(), newNode);
}
currLevel++;
}
}
Không có nhận xét nào:
Đăng nhận xét