TreeView遞迴繫結地區列表

iDotNetSpace發表於2010-06-04
private Service svc = Service.GetInstance();   
DataSet allRegion;
protected void Page_Load(object
sender, EventArgs e)
    {
       
if(!
IsPostBack){
            InitPage();
        }
    }

   
private void
InitPage() {
       
string lang  = "sc"
;
        allRegion
=
svc.GetAllRegion(lang);
        AddNode(
0, null
);
       
    }

   
private void AddNode(int
fid, TreeNode fatherNode) {
        DataRow[] rows
= allRegion.Tables[0].Select("fid=" +
fid);
       
foreach(DataRow row in
rows){
            TreeNode node
= new TreeNode(row["name"].ToString(), row["id"
].ToString());
            node.Expanded
= false
;
           
if (fatherNode == null
)
            {
                trvRegion.Nodes.Add(node);
            }
           
else
{
                fatherNode.ChildNodes.Add(node);
            }
            AddNode(
int.Parse(row["id"
].ToString()), node);
        }
    }

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-664368/,如需轉載,請註明出處,否則將追究法律責任。

相關文章