using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class ex : System.Web.UI.Page
{
public DataTable ds = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
int parentid;
if (Request["parentid"] == "")
{
parentid = 0;
}
else
{
parentid =Convert.ToInt32(Request["parentid"]);
}
databind();
treebind(0);
}
public void databind()
{
SqlConnection myconn = db.openconn();
if (myconn.State == ConnectionState.Closed)
{
myconn.Open();
}
string sql = "select * from aclass";
SqlDataAdapter sda = new SqlDataAdapter(sql, myconn);
sda.Fill(ds);
}
public void treebind(int pd)
{
string parentid = "parent_id=" + pd;
DataRow[] dr = ds.Select(parentid);
//Response.Write(dr.Length);
for (int i = 0; i < dr.Length; i++)
{
if (Convert.ToInt32(dr[i][1]) == pd)
{
string cname =dr[i][2].ToString();
int j = Convert.ToInt32(dr[i][0]);
Response.Write("<ul><li><a href='ex.aspx?id="+dr[i][0]+"&parentid="+dr[i][1]+"'>"+cname+"</a>");
treebind(j);
Response.Write("</li></ul>");
}
}
}
}