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

C#递归在dropdownlist显示树状

2008-07-08 16:42 441 查看
public void bind()

private void BindingCWAList(DropDownList ddlID, DataSet ds) //ddlID是DropDownList控件的ID

private void InitList(DropDownList ddlID, int parentID, DataSet catagoryDS, string indent)

{

//Select后边的是DataSet里面的列名

System.Data.DataRow[] currRows = catagoryDS.Tables[0].Select("ColumnFatherld=" + parentID.ToString(), "ColumnFatherld ASC");

int count = currRows.Length;

DataRow catagoryRow;

for (int i = 0; i < count; i++)

{

catagoryRow = currRows[i];

System.Web.UI.WebControls.ListItem item = new System.Web.UI.WebControls.ListItem(indent + catagoryRow["ColunmnName"].ToString(), catagoryRow["ColumnId"].ToString());

ddlID.Items.Add(item);

InitList(ddlID, Int32.Parse(catagoryRow["ColumnId"].ToString()), catagoryDS, indent + "……");

}

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