private void LoadData()
{
//gridView绑定数据
DataTable deptDt = GetDeptCustomsByWhere(string.Format("ParentID={0}", 0), null),
dt = deptDt.Clone();//从deptDt获取表结构
DataSet ds = new DataSet();
if(deptDt.Rows.Count>0)
{
foreach (DataRow row in deptDt.Rows)
{
dt.Rows.Add(row.ItemArray);//向dt中添加父节点
DataTable deptSonDt = GetDeptCustomsByWhere(string.Format("ParentID={0}", row["ID"]),null);
if (deptSonDt.Rows.Count>0)
{
foreach (DataRow dataRow in deptSonDt.Rows )
{
dt.Rows.Add(dataRow.ItemArray);//添加当前节点的子节点
}
}
}
}
gvList.DataSource = dt;
gvList.DataBind();
}
网络搜索结果: