Hi everyone...
I have populated a treeview. (like Category.JPG in the zip file), Now I am getting the datatable containing the treeview node values. and on the basis of that I need to make "checked" the check boxes at the time of page load. I am getting the Parent nodes only by using the following code below. But unable to get the child nodes.
DataTable dt = ds1.Tables[0];
foreach (TreeNode node in TreeViewArticleCatagory.Nodes)
{
foreach (DataRow dr in dt.Rows)
{
if (Convert.ToString(dr["Item"]) == node.Value)
{
node.Checked = true;
//TreeViewArticleCatagory.SelectedNode.Checked = true;
}
}
}
Please help me....
Thanks in advance.....
Loading
Arindam RudraPosted Aug 25, 2010, 6:53 AM
private void methode()
{
ds1 = new DataSet();
ds1 = oCategory.GetCategoriesOfArticle(ArticleID); // Use your own methode
if (ds1 !=null && ds1.Tables[0].Rows.Count > 0)
{
foreach (TreeNode node in TreeViewArticleCatagory.Nodes)
{
CheckNodes(node);
}
}
}
private void CheckNodes(TreeNode _node)
{
if (_node.ChildNodes.Count > 0)
{
CheckIfNodeValueExistsInDataTable(_node, ds1);
foreach (TreeNode _childNode in _node.ChildNodes)
{
CheckNodes(_childNode);
}
}
else
{
CheckIfNodeValueExistsInDataTable(_node, ds1);
}
}
private void CheckIfNodeValueExistsInDataTable(TreeNode _node, DataSet _dsCatogories)
{
DataTable dtNodes = _dsCatogories.Tables[0];
DataRow[] drow= dtNodes.Select("Item='" + _node.Value+"'");
if (drow != null && drow.Length > 0)
{
_node.Checked = true;
}
}