日期:2014-05-17 浏览次数:20546 次
/// <summary>
/// TreeView控件绑定
/// </summary>
private void TreeViewBind()
{
menulist = Security_MenuBLL.GetList("", "to_number(F4_A404) asc");
DataSet ds = ConvertToDataSet<Security_MenuEntity>(menulist); //数据源读取所有数据
DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = "F3_A404='0'"; //筛选父ID=0为顶级分类
TreeView1.ShowCheckBoxes = TreeNodeTypes.All;
foreach (DataRowView drv in dv)
{
TreeNode node = new TreeNode();
node.Text = drv["F1_A404"].ToString();
node.Value = drv["OID_A404"].ToString();
node.Expanded = false;
TreeView1.Nodes.Add(node);
AddReplies(dv, node);
}
}
/// <summary>
/// 递归绑定子节点
/// </summary>
private void AddReplies(DataView dv, TreeNode node)
{
dv.RowFilter = "F3_A404='" + node.Value + "'";
foreach (DataRowView row in dv)
{
TreeNode replyNode = new TreeNode();
replyNode.Text = row["F1_A404"].ToString();
replyNode.Value = row["OID_A404"].ToString();
replyNode.Expanded = false;