/// <summary>
/// 綁定文件分類
/// </summary>
public void bind()
{
//獲取數據集
DataSet ds = new DataSet();
ds = ec.ExecuteSelectCmmond("select * from t_Column where U_UserID=" + HttpContext.Current.Request.Cookies["NameID"].Value + "", ds);
BindingCWAList(DropDownList1, ds);
}
private void BindingCWAList(DropDownList ddlID, DataSet ds) //ddlID是DropDownList控件的ID
{
DropDownList1.Items.Clear();
//此處創建頂極分類,Value=0(如不需要,可以刪除此行)
ddlID.Items.Add(new ListItem("請選擇目錄", "0"));
InitList(ddlID, 0, ds, "");
}
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 + "……");
}
}