List<column_Model> ddlList = new List<column_Model>();
/// <summary>
/// 绑定父栏目
/// </summary>
/// <param name="ddlColumn">栏目下拉控件</param>
public void BindFather(DropDownList ddlColumn)
{
ddlColumn.Items.Add(new ListItem("请选择栏目...", "0"));
ddlList = DAL.column.Select();
if (ddlList!=null)
{
foreach (column_Model item in ddlList)
{
if (item.parentId=="0")
{
string columnId = item.columnId;
string columnName = item.columnName;
columnName = "" + columnName;
ddlColumn.Items.Add(new ListItem(columnName, columnId));
string sonParentId = columnId;
string blank ="├";
BindNode(sonParentId, blank, ddlColumn);
}
}
ddlColumn.DataBind();
}
}
/// <summary>
/// 绑定子栏目
/// </summary>
/// <param name="parentid">父栏目ID</param>
/// <param name="blank">间隔符号</param>
/// <param name="ddlColumn">栏目下拉控件</param>
public void BindNode(string parentid, string blank, DropDownList ddlColumn)
{
List<column_Model> sonList = getChild(parentid);
foreach (column_Model item in sonList)
{
string columnId = item.columnId;
string columnName = item.columnName;
columnName = blank + columnName;
ddlColumn.Items.Add(new ListItem(columnName, columnId));
string sonParentId = columnId;
string blank2 = blank + "─";
BindNode(sonParentId, blank2, ddlColumn);
}
}
/// <summary>
/// 根据父栏目ID获取子栏目
/// </summary>
/// <param name="parentId">父栏目ID</param>
/// <returns></returns>
public List<column_Model> getChild(string parentId)
{
List<column_Model> sonList = new List<column_Model>();
foreach (column_Model item in ddlList)
{
if (item.parentId==parentId)
{
sonList.Add(item);
}
}
return sonList;
}