#region "Deloy By Ngo Gia Phuc"
/* Looading the Category tree to show on the page */
private void getTreeView()
{
DataSet ds = new DataSet();
IFuncControl = new INSFunctionsControl();
ds = IFuncControl.LoadData();//.GetDataTree(pUserID);
tvFunction.Nodes.Clear(); --tvfunction là ten cua treeview
try
{
if (ds.Tables[0].Rows.Count > 0)
{
int currLevel = 0;
int maxLevel = Int32.Parse(ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["Level"].ToString());
int topLevel = Int32.Parse(ds.Tables[0].Rows[0]["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["Parent"].ToString();
int catid = Convert.ToInt32(dbRow["ID"].ToString());
TreeNode newNode = CreateNode(dbRow["Description"].ToString(), dbRow["ID"].ToString(), true, dbRow["Path"].ToString());
if (parentid == "0" || parentid == "448" )
{
tvFunction.Nodes.Add(newNode);
}
else
((TreeNode)listNode[parentid]).ChildNodes.Add(newNode);
tmplistNode.Add(newNode.Value.ToString(), newNode);
}
currLevel++;
}
}
}
catch
{
}
}
/* Creating the text and values to getout the treeView */
private TreeNode CreateNode(string text, string value, bool expanded, string controlKey)
{
TreeNode node = new TreeNode();
node.Text = text;
node.NavigateUrl = FormatURL(value, controlKey);
node.Value = value;
//node.Expanded = expanded;
return node;
}
#endregion
Không có nhận xét nào:
Đăng nhận xét