protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable table = bllSite.GetChannelNames(CurrentUser.ParkID);
BindChannelType(table, 0, 0);
}
}
//遞歸方法取
private void BindChannelType(DataTable dt, int categoryid, int layer)
{
DataView dv = new DataView(dt);
dv.RowFilter = " Pid= " + categoryid.ToString(); //過濾
if (categoryid != 0)
{
layer++; //默認為第一層
}
foreach (DataRowView drv in dv)
{
string span = "";
if (categoryid != 0)
{
for (int i = 0; i layer; i++)//父級菜單不縮進
{
span += " ";
}
span += "└";
}
ListItem li = new ListItem();
li.Text = span + drv["ChannelName"].ToString();
li.Value = drv["Id"].ToString();
this.ddlChannel.Items.Add(li);
BindChannelType(dt, Convert.ToInt32(drv["Id"]), layer);
}
}
更多關(guān)于asp.net相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《asp.net字符串操作技巧匯總》、《asp.net操作XML技巧總結(jié)》、《asp.net文件操作技巧匯總》、《asp.net ajax技巧總結(jié)專題》及《asp.net緩存操作技巧總結(jié)》。