豆腐坊

自娱自乐

导航

由数据库表中数据递归填充DropDownList

 

        private void BindingCWAList(DropDownList ddlID) //ddlID是DropDownList控件的ID
        
{
            ddlCWA.Items.Clear();
            DataSet ds ;
           
//此处的GetAll方法取出的是所需要的数据DataSet
            ds = org.jhes.dio.CW_Assort.cCWAssort.GetAll(null);
            
//此处创建顶极分类,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("pcwa_id="+parentID.ToString(),"cwa_id 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["CWA_Name"].ToString(),catagoryRow["CWA_ID"].ToString());
                ddlID.Items.Add(item);
                InitList(ddlID,Int32.Parse(catagoryRow[
"CWA_ID"].ToString()),catagoryDS,indent + "..");
            }

        }

posted on 2004-12-22 10:03  豆腐  阅读(213)  评论(0)    收藏  举报