无限级分根据当前Id读取下级Id
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Configuration;
using System.Data.SqlClient;
public partial class nextclassid : System.Web.UI.Page
{
protected static string connectionString = ConfigurationManager.AppSettings["ConnStr"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
int classid = Convert.ToInt32(Request.QueryString["id"]);
DataList1.DataSource = GetListClass(classid);
DataList1.DataBind();
}
public DataTable GetListClass(int ClassId)
{
SqlConnection Conn = new SqlConnection(connectionString);
Conn.Open();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from ArticleClass", Conn);
//DataSet ds = new DataSet();
//sda.Fill(ds, "ArticleClass");
//DataTable DT = new DataTable();
//DT = (DataTable)ds.Tables["ArticleClass"];
DataTable DT = new DataTable();
sda.Fill(DT);
DataRow myrow;
DataTable mytab = new DataTable();
mytab.Columns.Add("Id");
mytab.Columns.Add("Title");
mytab.Clear();
for (int i = 0; i < DT.Rows.Count; i++)
{
if (ClassId == (int)DT.Rows[i]["ParentId"])
{
myrow = mytab.NewRow();
myrow[0] = DT.Rows[i]["Id"];
myrow[1] = DT.Rows[i]["Title"];
mytab.Rows.Add(myrow);
myrow.AcceptChanges();
}
}
if (mytab.Rows.Count == 0) mytab = GetListClass(0);
return mytab;
}
}