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);
}
}
更多关于asp.net相关内容感兴趣的读者可查看本站专题:《asp.net字符串操作技巧汇总》、《asp.net操作XML技巧总结》、《asp.net文件操作技巧汇总》、《asp.net ajax技巧总结专题》及《asp.net缓存操作技巧总结》。