日期:2014-05-17 浏览次数:20840 次
public partial class test : System.Web.UI.Page
{
string nodes = string.Empty;
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
string str = ConfigurationManager.ConnectionStrings["connStr"].ToString();
SqlConnection conn = new SqlConnection(str);
SqlDataAdapter adp = new SqlDataAdapter("select * from tab", conn);
adp.Fill(dt);
GetAllNodes("1");
Response.Write(nodes);
}
private void GetAllNodes(string id)
{
DataRow[] drs = dt.Select("up_id=" + id);
if (drs.Length <= 0) return;
foreach (DataRow dr in drs)
{
nodes += dr["id"].ToString() + ",";
GetAllNodes(dr["up_id"].ToString());
}
}
}
GetAllNodes(dr["up_id"].ToString());