DropDownList顯示的C#遞歸實(shí)現(xiàn)淺析
C#遞歸實(shí)現(xiàn)DropDownList顯示之前首先我們來看看對于DropDownList的理解,對于有些形式的輸入,用戶必須從適用選項(xiàng)列表中選擇一個(gè)選項(xiàng)。例如,軟件公司可能要?jiǎng)?chuàng)建一個(gè)支持網(wǎng)站,用戶可以在其中找到關(guān)于該公司各種軟件產(chǎn)品的常見問題的答案。用戶尋找問題的答案時(shí),如果在用戶搜索的關(guān)鍵字旁邊,可以選擇問題是針對于哪個(gè)軟件產(chǎn)品的,將有助于他更容易找到問題的答案。
在這種情況下,適合收集這種信息輸入的Web控件是DropDownList。DropDownList Web控件創(chuàng)建一個(gè)包含多個(gè)選項(xiàng)的下拉列表,用戶可以從中選擇一個(gè)選項(xiàng),那讓我們來看看DropDownList顯示的C#遞歸實(shí)現(xiàn)實(shí)例:
- /**//// <summary>
- ////DropDownList顯示的C#遞歸實(shí)現(xiàn)
- /// 綁定文件分類
- /// </summary>
- public void bind()
- {
- //獲取數(shù)據(jù)集
- 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();
- //此處創(chuàng)建頂極分類,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 + "……");
- }
- }
DropDownList顯示的C#遞歸實(shí)現(xiàn)的基本內(nèi)容就向你介紹到這里,希望對你了解和學(xué)習(xí)DropDownList顯示的C#遞歸實(shí)現(xiàn)有所幫助。
【編輯推薦】