我现在要实现的效果是:
给每个用户的权限具体到具体的目录。
所以,显示效果就应该像Csdn的“配置我感兴趣的社区”页面的效果一样,也即:
按目录层次结构显示出来。我现在采取的措施是:将CheckBox以及目录名称根据数据库数据读出来,并输出到页面。但是,总是不能实现层次结构,不知是否还有好的解决方案。

解决方案 »

  1.   

    public void ListClassInfo()
    {
    formContainer=(System.Web.UI.HtmlControls.HtmlForm)Page.FindControl("Form1");
    for(int i=0;i<firstClassInfo().Tables[0].Rows.Count;i++)
    {
    //隐藏按钮,用来保存目录名称对应的ID,以存入权限表中
    System.Web.UI.HtmlControls.HtmlInputHidden theValueOfFirstClass=new HtmlInputHidden();
    theValueOfFirstClass.Value=firstClassInfo().Tables[0].Rows[i]["FcID"].ToString();
    //添加、修改、删除权限选项
    System.Web.UI.HtmlControls.HtmlInputCheckBox operOfFirst=new HtmlInputCheckBox();
    operOfFirst.ID="operOfFirst";
    operOfFirst.Value="1";
    Literal firstClassName=new Literal();
    firstClassName.Text=firstClassInfo().Tables[0].Rows[i]["FcName"].ToString();
    Literal operOfFirstText=new Literal();
    operOfFirstText.Text="添加、修改、删除";
    //浏览权限选项
    HtmlInputCheckBox viewOfFirst=new HtmlInputCheckBox();
    viewOfFirst.ID="viewOfFirst";
    viewOfFirst.Value="2";
    Literal viewOfFirstText=new Literal();
    viewOfFirstText.Text="浏览";
    //审核权限选项
    HtmlInputCheckBox auditOfFirst=new HtmlInputCheckBox();
    auditOfFirst.ID="auditOfFirst";
    auditOfFirst.Value="3";
    Literal auditOfFirstText=new Literal();
    auditOfFirstText.Text="审核";
    //用来实现格式化显示
    Literal spaceFormatOfFirst=new Literal();
    spaceFormatOfFirst.Text="<BR>"+"&nbsp;&nbsp;&nbsp;&nbsp;";
    //将定义的控件按显示顺序输出到页面
    formContainer.Controls.Add(theValueOfFirstClass);
    formContainer.Controls.Add(firstClassName);
    formContainer.Controls.Add(operOfFirst);
    formContainer.Controls.Add(operOfFirstText);
    formContainer.Controls.Add(viewOfFirst);
    formContainer.Controls.Add(viewOfFirstText);
    formContainer.Controls.Add(auditOfFirst);
    formContainer.Controls.Add(auditOfFirstText);
    formContainer.Controls.Add(spaceFormatOfFirst); int fcid=Convert.ToInt32(firstClassInfo().Tables[0].Rows[i]["FcID"].ToString());
    if(isSecond(fcid))
    {
    for(int j=0;j<secondClassInfo(fcid).Tables[0].Rows.Count;j++)
    {
    System.Web.UI.HtmlControls.HtmlInputHidden theValueOfSecondClass=new HtmlInputHidden();
    theValueOfSecondClass.Value=secondClassInfo(fcid).Tables[0].Rows[j]["ScID"].ToString();
    System.Web.UI.HtmlControls.HtmlInputCheckBox operOfSecond=new HtmlInputCheckBox();
    operOfSecond.ID="operOfSecond";
    operOfSecond.Value="1";
    Literal secondClassName=new Literal();
    secondClassName.Text=secondClassInfo(fcid).Tables[0].Rows[j]["ScName"].ToString();
    Literal operOfSecondText=new Literal();
    operOfSecondText.Text="添加、修改、删除";
    //浏览权限选项
    HtmlInputCheckBox viewOfSecond=new HtmlInputCheckBox();
    viewOfSecond.ID="viewOfSecond";
    viewOfSecond.Value="2";
    Literal viewOfSecondText=new Literal();
    viewOfSecondText.Text="浏览";
    //审核权限选项
    HtmlInputCheckBox auditOfSecond=new HtmlInputCheckBox();
    auditOfSecond.ID="auditOfSecond";
    auditOfSecond.Value="3";
    Literal auditOfSecondText=new Literal();
    auditOfSecondText.Text="审核";
    Literal spaceFormatOfSecond=new Literal();
    if(getSecondCountOfFirst(fcid)==1)
    {
    spaceFormatOfSecond.Text="<BR>"+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    }
    else if(getSecondCountOfFirst(fcid)==2)
    {
    spaceFormatOfSecond.Text="<BR>"+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    }
    formContainer.Controls.Add(theValueOfSecondClass);
    formContainer.Controls.Add(secondClassName);
    formContainer.Controls.Add(operOfSecond);
    formContainer.Controls.Add(operOfSecondText);
    formContainer.Controls.Add(viewOfSecond);
    formContainer.Controls.Add(viewOfSecondText);
    formContainer.Controls.Add(auditOfSecond);
    formContainer.Controls.Add(auditOfSecondText);
    formContainer.Controls.Add(spaceFormatOfSecond);
    int scid=Convert.ToInt32(secondClassInfo(fcid).Tables[0].Rows[j]["ScID"].ToString());
    if(isThird(scid))
    {
    for(int t=0;t<thirdClassInfo(scid).Tables[0].Rows.Count;t++)
    {
    //隐藏按钮,用来保存目录名称对应的ID,以存入权限表中
    System.Web.UI.HtmlControls.HtmlInputHidden theValueOfThirdClass=new HtmlInputHidden();
    theValueOfThirdClass.Value=thirdClassInfo(scid).Tables[0].Rows[t]["TcID"].ToString();
    //添加、修改、删除权限选项
    System.Web.UI.HtmlControls.HtmlInputCheckBox operOfThird=new HtmlInputCheckBox();
    operOfThird.ID="operOfThird";
    operOfThird.Value="1";
    Literal ThirdClassName=new Literal();
    ThirdClassName.Text=thirdClassInfo(scid).Tables[0].Rows[t]["TcName"].ToString();
    Literal operOfThirdText=new Literal();
    operOfThirdText.Text="添加、修改、删除";
    //浏览权限选项
    HtmlInputCheckBox viewOfThird=new HtmlInputCheckBox();
    viewOfThird.ID="viewOfThird";
    viewOfThird.Value="2";
    Literal viewOfThirdText=new Literal();
    viewOfThirdText.Text="浏览";
    //审核权限选项
    HtmlInputCheckBox auditOfThird=new HtmlInputCheckBox();
    auditOfThird.ID="auditOfThird";
    auditOfThird.Value="3";
    Literal auditOfThirdText=new Literal();
    auditOfThirdText.Text="审核";
    Literal spaceFormatOfThird=new Literal();
    if(getThirdCountOfSecond(scid)==1)
    {
    //用来实现格式化显示
    spaceFormatOfThird.Text="<BR>";
    }
    //将定义的控件按显示顺序输出到页面
    formContainer.Controls.Add(theValueOfThirdClass);
    formContainer.Controls.Add(ThirdClassName);
    formContainer.Controls.Add(operOfThird);
    formContainer.Controls.Add(operOfThirdText);
    formContainer.Controls.Add(viewOfThird);
    formContainer.Controls.Add(viewOfThirdText);
    formContainer.Controls.Add(auditOfThird);
    formContainer.Controls.Add(auditOfThirdText);
    formContainer.Controls.Add(spaceFormatOfThird);
    }
    }
    }
    }
    }
    }
      

  2.   

    如果想让用户看到有层次的目录结构  层次目录是固定的  在用户选择相对应的栏目的时候 把相关这个用户选择的分栏目的id写到数据库,每次用户打开权限层次目录的时候 从数据读出来他选择的分栏目id 循环整个页面上分栏目,对应着把选择项加上去
      

  3.   

    很难么?参照这个帖子里我建议的recursionhttp://community.csdn.net/Expert/topic/4457/4457791.xml?temp=.8854181
      

  4.   

    我的数据是从三张表的来得,表结构:
    一级目录
    列名  数据类型
    FcID   int(自增)
    FcName varchar(10)
    二级目录
    ScID   int(自增)
    FcID    int(一级目录的FcID)
    ScName    varchar(10)
    三级目录
    TcID    int(自增)
    ScID    int(二级目录的ScID)
    TcName   varchar(10)
    而思归所列贴内容相当于,给TreeView绑定数据的递归
    如:
    //递归添加树的节点
    public void AddTree(int ParentID,TreeNode pNode) 
    {
    DataSet ds=(DataSet) this.ViewState["ds"]; 
    DataView dvTree = new DataView(ds.Tables[0]);
    //过滤ParentID,得到当前的所有子节点
    dvTree.RowFilter =  "[PARENTID] = " + ParentID; foreach(DataRowView Row in dvTree) 
    {
    TreeNode Node=new TreeNode() ;
    if(pNode == null) 
    {    //添加根节点
    Node.Text = Row["ConText"].ToString();
    Node.NavigateUrl=Row["ContTarget"].ToString();
    Node.Target="main";
    TreeMenu.Nodes.Add(Node);
    Node.Expanded=true;
    AddTree(Int32.Parse(Row["ID"].ToString()), Node);    //再次递归

    else 
    {   //添加当前节点的子节点
    Node.Text = Row["ConText"].ToString();
    Node.NavigateUrl=Row["ContTarget"].ToString();
    Node.Target="main";
    pNode.Nodes.Add(Node);
    Node.Expanded = true;
    AddTree(Int32.Parse(Row["ID"].ToString()),Node);     //再次递归
    }
    }                   
    }           
    但我现在这个好像不成啊?
      

  5.   

    create a relationshipselect FCID,FcName as Name from table1;
    select SCIF,FCID,ScName as Name from table2;
    select TCID,ScID,TcName as Name from table3
    DataSet ds = ...
    ds.Relations.Add("rel1", ds.Tables[0].Columns["FcID"],ds.Tables[1].Columns["FcID"]);
    ds.Relations.Add("rel2", ds.Tables[1].Columns["ScID"],ds.Tables[1].Columns["ScID"]);
    StringBuilder mystr=new StringBuilder();GetString(ds.Tables[0], mystr, 1);void GetString(DataRow[] drs, StringBuilder mystr, int depth)
    {
    foreach(DataRow dr in drs)
    {
    mystr.Append(dr["Name"].ToString()+"<br/>");
    if (depth < 2)
    {
    GetString(dr.GetChildRows("rel" + i.ToString()),mystr,depth+1);
    }
    }
    }
      

  6.   

    ds.Relations.Add("rel1", ds.Tables[0].Columns["FcID"],ds.Tables[1].Columns["FcID"]);
    ds.Relations.Add("rel2", ds.Tables[1].Columns["ScID"],ds.Tables[2].Columns["ScID"]);
      

  7.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    SqlDataAdapter CmdState=new SqlDataAdapter("Select a.FcID,a.fcname From Info_Fircata a;Select b.scid,b.scname From Info_Seccata b;Select c.tcid,c.tcname From Info_Thircata c",conn);
    DataSet DsState=new DataSet();
    CmdState.Fill(DsState);
    //给DataSet添加关系
    DsState.Relations.Add("rel1", DsState.Tables[0].Columns["FcID"],DsState.Tables[1].Columns["FcID"]);
    DsState.Relations.Add("rel2", DsState.Tables[1].Columns["ScID"],DsState.Tables[2].Columns["ScID"]);
    StringBuilder mystr=new StringBuilder();
    //调用递归函数
    GetString(DsState.Tables[0], mystr, 1);
    }void GetString(DataRow[] drs, StringBuilder mystr, int depth)
    {
        foreach(DataRow dr in drs)
          {
    mystr.Append(dr["FcName"].ToString()+"<br/>");
    if (depth < 2)
    {
    GetString(dr.GetChildRows("rel" + depth.ToString()),mystr,depth+1);
    }
          }
    }
    编译时出错:
    C:\Inetpub\wwwroot\20051201\Audit\1.aspx.cs(34): 与“_20051201.Audit._1.GetString(System.Data.DataRow[], System.Text.StringBuilder, int)”最匹配的重载方法具有一些无效参数
    C:\Inetpub\wwwroot\20051201\Audit\1.aspx.cs(34): 参数“1” : 无法从“System.Data.DataTable”转换为“System.Data.DataRow[]”
      

  8.   

    GetString(DsState.Tables[0], mystr, 1);
    改为
    GetString(DsState.Tables[0].Rows, mystr, 1);
    还是一样的错。
      

  9.   

    sorry, tryGetString(ds.Tables[0], mystr, 1);
    ==>
    GetString(ds.Tables[0].Select(), mystr, 1);ds.Tables[0].Rows is DataRowCollection
      

  10.   

    显示的效果是树形的。
    但是,也不是一般所说的树形菜单,如TreeView等。
    我要的就像Csdn的“配置我感兴趣的社区”
    http://community.csdn.net/Expert/member/select_room.asp
    谢谢。
      

  11.   

    谢谢saucer(思归)老大。同过您的帮助,语法没有问题,编译通过。但是,
    运行时,出现
    列“FcName”不属于表 Table1。
    即行 39:  foreach(DataRow dr in drs)
    行 40:  {
    行 41:  mystr.Append(dr["FcName"].ToString()+"<br/>");
    行 42:  Response.Write(mystr);
    行 43:  if (depth < 2)
    中的mystr.Append(dr["FcName"].ToString()+"<br/>");
    FcName不属于表Table1.
    难道此处的dr[""]不是Table[0]中的字段名称吗?
    谢谢。
      

  12.   

    you will notice I modify the sql select statement to return the same Name field,select FCID,FcName as Name from table1;
    select SCIF,FCID,ScName as Name from table2;
    select TCID,ScID,TcName as Name from table3 yes, you are right, "i" should be "depth"