代码:
protected void GetCategories(DropDownList DropDownList, string id)
{
DataView MyDataView = new Caicai.DBHelper().ExecuteDataSet("select id,c_name,c_path from c_categories where c_parentid=" + id +" order by c_sort").Tables["Table"].DefaultView;
foreach (DataRowView MyDataRowView in MyDataView)
{
AddTo = new String(' ', (MyDataRowView[2].ToString().Split('|').Length - 1) * 2) + "└ ";
DropDownList.Items.Add(new ListItem(AddTo + MyDataRowView[1].ToString(), MyDataRowView[0].ToString()));
this.GetCategories(DropDownList,MyDataRowView[0].ToString());
}
转自:阿佛尔[www.afoer.com]
http://www.afoer.com/html/2007-08/1187272045.html
调用:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GetCategories(DropDownList1,"0");
}
}