下面是从数据库的两个表找出数据并绑定的,但不是用递归
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
run(TreeView1.Nodes, "0");
}
}public void run(TreeNodeCollection nd, string sname)
{
string id;
if (Request["id"] != null)
{
id = Request.QueryString["id"].ToString();
}
else
{
id = "";
}
DataSet ds = new DataSet();
ds = DB.go("select cname,tu,od,other from max_type order by od desc");
if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr0 in ds.Tables[0].Rows)
{
TreeNode tn = new TreeNode();
tn.Text = (dr0["cname"].ToString()); if (id == dr0["other"].ToString())
{
tn.Expanded = true;
}
else
{
tn.Expanded = false;
}
tn.ImageUrl = "images/tree/" + dr0["tu"].ToString();
//
nd.Add(tn);
DataSet ds1 = new DataSet();
ds1 = DB.go("select cname from small_type where max_type='" + tn.Text + "'");
if (ds1.Tables[0].Rows.Count > 0)
{
tn.SelectAction = TreeNodeSelectAction.Expand;
foreach (DataRow dr1 in ds1.Tables[0].Rows)
{
TreeNode tn1 = new TreeNode();
tn1.Text = (dr1["cname"].ToString());
tn1.NavigateUrl = "more.aspx?id=" + dr0["other"].ToString() + "&idd=" +Server.UrlEncode(tn1.Text);
tn1.ImageUrl = "images/2.gif";
tn.ChildNodes.Add(tn1);
}
}
else
{
tn.NavigateUrl = "more.aspx?id=" + dr0["other"].ToString();
}
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
run(TreeView1.Nodes, "0");
}
}public void run(TreeNodeCollection nd, string sname)
{
string id;
if (Request["id"] != null)
{
id = Request.QueryString["id"].ToString();
}
else
{
id = "";
}
DataSet ds = new DataSet();
ds = DB.go("select cname,tu,od,other from max_type order by od desc");
if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr0 in ds.Tables[0].Rows)
{
TreeNode tn = new TreeNode();
tn.Text = (dr0["cname"].ToString()); if (id == dr0["other"].ToString())
{
tn.Expanded = true;
}
else
{
tn.Expanded = false;
}
tn.ImageUrl = "images/tree/" + dr0["tu"].ToString();
//
nd.Add(tn);
DataSet ds1 = new DataSet();
ds1 = DB.go("select cname from small_type where max_type='" + tn.Text + "'");
if (ds1.Tables[0].Rows.Count > 0)
{
tn.SelectAction = TreeNodeSelectAction.Expand;
foreach (DataRow dr1 in ds1.Tables[0].Rows)
{
TreeNode tn1 = new TreeNode();
tn1.Text = (dr1["cname"].ToString());
tn1.NavigateUrl = "more.aspx?id=" + dr0["other"].ToString() + "&idd=" +Server.UrlEncode(tn1.Text);
tn1.ImageUrl = "images/2.gif";
tn.ChildNodes.Add(tn1);
}
}
else
{
tn.NavigateUrl = "more.aspx?id=" + dr0["other"].ToString();
}
}
}
}
解决方案 »
- 请教一下,关于POST传参的问题
- 急,我用COOKIES标记登录信息,现在添加数据的时候,我添加的跑到别人名下,别人的跑到我的名下
- 求一条Sql统计语句
- 谁能推荐一款电子书制作程序?
- 请问在ASP.NET中如何动态设置meta标签中的content属性
- 我快疯了
- 两个小问题,送分拉
- 在线等待,帮我解释一下代码中的一点问题好吗?
- (斑竹,高手请关注)怎么在DataGird中的HtmlSelect控件绑定(可行即给分)(两贴100分)
- 问一个订单系统的问题
- 邮件无法发送到 SMTP 服务器。传输错误代码为 0x800ccc15。服务器响应为 not available
- 水晶報表logo換掉后ie瀏覽要求輸入用戶名密碼如何解決﹖
把XML文档绑到某个节点上这个功能居然没有了。