C # recursively display the tree in dropdownlist

Source: Internet
Author: User

/// <Summary>
/// File category
/// </Summary>
Public void bind ()
{
// Obtain the dataset
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 is the ID of the DropDownList Control
{
DropDownList1.Items. Clear ();
// Create the vertex category here, Value = 0 (you can delete this row if you do not need it)
DdlID. Items. Add (new ListItem ("Select Directory", "0 "));
InitList (ddlID, 0, ds ,"");
}


Private void InitList (DropDownList ddlID, int parentID, DataSet catagoryDS, string indent)
{
// The column name in DataSet is behind the Select statement.
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 + "...... ");
}
}
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.