protected ArrayList arAllDisplayId;
protected DataTable ol;
ArrayList ii=new ArrayList();
    
private void ShowAllControl(Control Ctl)
{
foreach(Control ctl in Ctl.Controls)
{
Response.Write(ctl.ClientID+" "+ctl.GetType().Name+"<br>");
if(ctl.HasControls())
ShowAllControl(ctl);
}
}
 
private void CreatTree(Person pPerson)
{
tvTree.ShowPlus=true;  // 第一处 
tvTree.ShowLines=true; ol=dtHrbWebMode.Copy();
ol.Columns.Add("IsDisplay",typeof(bool));
ol.PrimaryKey=new DataColumn[]{ol.Columns["ModelID"]}; foreach(int row in pPerson.alRightList)
{
SetDisplay(row);
}
InitTree(tvTree.Nodes,0);
}

private void SetDisplay(int iUpOperateId)
{
DataRow row=ol.Rows.Find(iUpOperateId);
if(row["IsDisplay"].ToString()!="True")
{
row["IsDisplay"]=true;
} if((int)(row["UpModelID"])!=0)
{
SetDisplay((int)row["UpModelID"]);
}
}
private void InitTree(TreeNodeCollection tnc,int parentID)
{
DataView dv=new DataView();
dv.Table=ol;
dv.RowFilter="UpModelID="+parentID.ToString()+" AND IsDisplay=True";
TreeNode tn;
foreach(DataRowView drv in dv)
{
tn=new TreeNode();
tn.Text=drv["ModelTitle"].ToString();
tn.NodeData=drv["ModelID"].ToString(); //第二处
if((bool)drv["IsLeaf"])
{
tn.Target="main";
tn.Checked=true; 
tn.NavigateUrl=drv["PageUrl"].ToString()+"?lanmuId="+drv["ModelID"].ToString()+"&lanmuName="+drv["ModelTitle"].ToString();

}
tnc.Add(tn);
InitTree(tnc[tnc.Count-1].Nodes,(int)drv["ModelID"]);//第三处
}
}
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
//this.HrbSpecial();
this.Label1.Text="所选记录由“"+this.Request["lanmuName"].ToString()+"”复制到";
this.SessionOK();
this.CreatTree((Person)this.Session["CurrentPerson"]);
}
            
} private void FindCheck(TreeNodeCollection Nds)
{
foreach(TreeNode node in Nds)
{
if(node.Checked)
{
ii.Add(node.NodeData);//第四处
}
if(node.Nodes.Count!=0)//第五处
{
FindCheck(node.Nodes);// 第六处
}
}
}这是2003里的 代码 转到2005里 出现六处错误  请大家帮我看看  初学啊 !!

解决方案 »

  1.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using Microsoft.Web.UI.WebControls;
    namespace Web
    {
    /// <summary>
    /// RoleOperationSet 的摘要说明。
    /// </summary>
    public partial class RoleOperationSet : Web.WebFormBase
    {
    DataTable dtRole_OperateList;
    //要打钩的操作编号
    Model.Role role=null;
    /// <summary>
    /// 本页的角色
    /// </summary>
    private Model.Role objRole
    {
    get
    {
       if(Session["Role"]==null)
       Session["Role"]=role;
    return (Model.Role)Session["Role"];
    }
    set
    {
    if(value==null)
    Session.Remove("Role");
        Session["Role"]=value;
    }
    }
    protected void Page_Load(object sender, System.EventArgs e)
    {
    SessionOK();
    if(!IsPostBack)
    {
    int RoleID=int.Parse(Request.QueryString["RoleID"]);
    objRole=BLL.RoleManager.GetRole(RoleID);
    labRoleName.Text="当前角色:"+"<font color='red'>"+objRole.RoleName+"</font>";
                    dtRole_OperateList=BLL.OperateManager.GetOperateList().Tables[Model.Operate.OPERATE_TABLE];

    InitTree(tvOperate.Nodes,0);
    tvOperate.Nodes[0].Expanded=true;
    this.SetAllTextBoxCss(this);
    }
    }
    //加载所有操作
    void InitTree(System.Web.UI.WebControls.TreeNodeCollection tnc, int UpOperateID)
    {
        DataView dv=new DataView();
    dv.Table=dtRole_OperateList;
                dv.RowFilter="UpOperateID="+UpOperateID.ToString();
    foreach(DataRowView drv in dv)
    {
        TreeNode tn=new TreeNode();
    tn.Text=drv[Model.Operate.OPERATE_NAME_FIELD].ToString();
    tn.NodeData=drv[Model.Operate.OPERATE_ID_PK].ToString();
    tn.CheckBox=(bool)drv[Model.Operate.OPERATE_ISLEAF_FIELD]?true:false;
    DataRow[] drc=objRole.operateList.Tables[Model.Operate.OPERATE_TABLE].Select(Model.Operate.OPERATE_ID_PK+"="+drv[Model.Operate.OPERATE_ID_PK].ToString());
    tn.Checked=drc.Length>0?true:false;
                    tnc.Add(tn);
    InitTree(tnc[tnc.Count-1].Nodes,(int)drv[Model.Operate.OPERATE_ID_PK]);
    }

    // /// <summary>
    // /// 返回应该打钩的节点数组
    // /// </summary>
    // /// <returns></returns>
    // ///         
    // void GetCheckedNodeIDList()
    // {     
    // al.Clear();
    // foreach(DataRow dr in objRole.operateList.Tables[Model.Operate.OPERATE_TABLE].Rows)
    // {
    // al.Add((int)dr[Model.Operate.OPERATE_ID_PK]);
    // GetCheckedNodeParentID((int)dr[Model.Operate.OPERATE_UPOPERATEID_FIELD]);
    // }
    // }
    // void GetCheckedNodeParentID(int ParentID)
    // {
    // if(!al.Contains(ParentID))
    // al.Add(ParentID);
    // DataRow[] drc=dtRole_OperateList.Select(Model.Operate.OPERATE_ID_PK+"="+ParentID.ToString());
    // if(drc.Length>0)
    //                GetCheckedNodeParentID((int)drc[0][Model.Operate.OPERATE_UPOPERATEID_FIELD]);
    //
    // }
    //获得用户选择的操作编号数组
    ArrayList alOperateIDs=new ArrayList();
    private void GetCustomSelectOperteID(System.Web.UI.WebControls.TreeNodeCollection tnc)
    {    
    foreach(TreeNode tn in tnc)
    {
    if(tn.Checked && tn.Nodes.Count==0)
    alOperateIDs.Add(int.Parse(tn.NodeData));
    if(tn.Nodes.Count>0)
    GetCustomSelectOperteID(tn.Nodes);
    }
    }
    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {     }
    #endregion protected void BtnRoleSave_Click(object sender, System.EventArgs e)
    {            
    alOperateIDs.Clear();
                GetCustomSelectOperteID(tvOperate.Nodes);
    if(alOperateIDs.Count>0)
    BLL.RoleManager.UpdateOperate(objRole,alOperateIDs);
    objRole.Dispose();
    objRole=null;//释放Session
    Response.Redirect("RoleManage.aspx");
    } protected void BtnRoleReset_Click(object sender, System.EventArgs e)
    {
    // tvOperate.Nodes.Clear();
    // InitTree(tvOperate.Nodes,0);
                //this.Refresh();
    this.Response.Redirect("rolemanage.aspx");
    }

    }
    }
    这里也出现了  同样的问题  这是两个工程里的  帮我看看大家  谢谢了 !!
      

  2.   

    基本都是一些属性名的变动
    参考第一个里面的,楼主应该可以改好第二个,加油;
    tvTree.ShowExpandCollapse = true;  // 第一处 
    tn.Value = drv["ModelID"].ToString(); //第二处 
    InitTree(tnc[tnc.Count - 1].ChildNodes, (int)drv["ModelID"]);//第三处 
    ii.Add(node.Value);//第四处 
    if (node.ChildNodes.Count != 0)//第五处 
    FindCheck(node.ChildNodes);// 第六处 
      

  3.   

    第二个也帮我改一下吧  谢谢  第一个 现在没有错误了 但是 我的树型菜单  运行之后  没有前面的 CheckBox 了  怎么改 哥们 谢谢了  
      

  4.   

    @第二个也帮我改一下吧  谢谢  
    自己动手了@第一个 现在没有错误了 但是 我的树型菜单  运行之后  没有前面的 CheckBox 了  怎么改 哥们 谢谢了  
    tvTree.ShowCheckBoxes = true;
      

  5.   

    tvTree.ShowCheckBoxes = true; 
    这句有 语法错误 !!
      

  6.   

    tvTree.ShowCheckBoxes = TreeNodeTypes.Leaf;
    应该是这样的吧  不过我要的 不是这个效果  这个运行效果是  都选中的 我想让他显示 但是默认都不选中  怎么办?
      

  7.   

    节点默认应该是不选中的啊。你试一下下面的代码。protected void Page_Load(object sender, EventArgs e)
            {
                if(!IsPostBack)
                {
                    TreeView1.ShowCheckBoxes = TreeNodeTypes.Leaf; // 如果只希望叶节点有checkbox
                    /*
                    TreeView1.ShowCheckBoxes = TreeNodeTypes.All; // 如果只希望所有节点有checkbox
                    TreeView1.ShowCheckBoxes = TreeNodeTypes.Parent; // 如果只希望中间节点有checkbox
                     */
                }
            }
    再不行你就把整个工程发过来,我帮你看看