Hello All,
I have a tree view control which I have to bind a dataset with multiple data tables in it, and have relations between them.
can you suggest how can I do that, I have tried many ways but none of them proved useful...
Thanks
Hello All,
I have a tree view control which I have to bind a dataset with multiple data tables in it, and have relations between them.
can you suggest how can I do that, I have tried many ways but none of them proved useful...
Thanks
Binding Data With ‘TreeView’ Control Asp.net 2.0 http://www.codeproject.com/KB/aspnet/DataTreeView.aspx
try this code, hope will be helpfull..I have just copy pasted code... you can change column name..
DataTable dt=new DataTable();
DataTable dt1 = new DataTable();
DataSet ds = new DataSet();
ds.Tables.Add(dt);
ds.Tables.Add(dt1);
ds.Relations.Add("children", dt.Columns["GSICCodeID"], dt1.Columns["GSICCodeID"]);
if (ds.Tables[0].Rows.Count > 0)
{
tvSicCode.Nodes.Clear();
Int32 i = 0;
foreach (DataRow masterRow in ds.Tables[0].Rows)
{
TreeNode masterNode = new TreeNode((string)masterRow["Description"], Convert.ToString(masterRow["GSicCodeID"]));
tvSicCode.Nodes.Add(masterNode);
foreach (DataRow childRow in masterRow.GetChildRows("Children"))
{
TreeNode childNode = new TreeNode((string)childRow["SICCodeDesc"], Convert.ToString(childRow["SICCodeID"]));
if (Convert.ToString(ds.Tables[1].Rows[i]["CarrierSICCode"]) != "")
childNode.Checked = true;
masterNode.ChildNodes.Add(childNode);
i++;
}
}
tvSicCode.CollapseAll();
}