您的位置:首页 > 编程语言 > ASP

ASP.NET - TreeView 增删

2015-09-17 16:13 645 查看
效果:

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using APManage.App_Code;
using System.Data.SqlClient;

namespace APManage
{
public partial class updateNodes : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.DropDownList1.DataSource = SQLHelper.ExecuteTable("select * from Tb_APCategory where ParentID = 1000", CommandType.Text);
this.DropDownList1.DataValueField = "ID";
this.DropDownList1.DataTextField = "CategoryName";
this.DropDownList1.DataBind();

List<category> inof = new List<category>();
SqlDataReader sdr = SQLHelper.ExcuteReader("select ID, CategoryName from Tb_APCategory where ParentID = 1000", CommandType.Text);
while (sdr.Read())
{
SqlDataReader sdr_2 = SQLHelper.ExcuteReader("select ID, CategoryName from Tb_APCategory where ParentID = " + sdr["ID"].ToString() + "", CommandType.Text);
while (sdr_2.Read())
{
inof.Add(new category(sdr_2["ID"].ToString(), sdr_2["CategoryName"].ToString()));
}
}

this.DropDownList2.DataSource = inof;
this.DropDownList2.DataValueField = "ID";
this.DropDownList2.DataTextField = "Name";
this.DropDownList2.DataBind();

//this.DropDownList2.DataSource = SQLHelper.ExecuteTable("select * from Tb_APCategory", CommandType.Text);
//this.DropDownList2.DataValueField = "";
//this.DropDownList2.DataTextField = "";
//this.DropDownList2.DataBind();
}

public class category
{
public category(string id, string name)
{
Id = id;
Name = name;
}

private string id;

public string Id
{
get { return id; }
set { id = value; }
}

private string name;

public string Name
{
get { return name; }
set { name = value; }
}
}
}
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: