使用循环控制两列输出

  //论坛首页二级关联菜单
  public string SecondMenu(string strParent)
  {
   string strSecondMenu =null;
   string sqlStr = "select [ID],[Name] from [Uk_BBSClass] where [ParentID]=" + strParent + "  order by [PrefaceID] asc";
   DataSet towDs = UnitLink.Component.Common.doMssql.GetDataSet(sqlStr,null);
   for(int dr = 0; dr < towDs.Tables[0].Rows.Count;dr++)
   {
    strSecondMenu += "<a href=topicList.aspx?c="+towDs.Tables[0].Rows[dr][0].ToString()+">"+towDs.Tables[0].Rows[dr][1].ToString()+"</a>&nbsp;";
    if(dr==2){break;}//只显示
   }
   towDs.Dispose();
   return strSecondMenu;
  }

  //这里是输出一级菜单
  public string FirstMenu()
  {
   string strFirstMenu =null;
   string sqlStr = "select [ID],[Name] from [Uk_BBSClass] where [ParentID]=0 order by [PrefaceID] asc";
   DataSet oneDs = UnitLink.Component.Common.doMssql.GetDataSet(sqlStr,null);
   string begin = "<table border=\"1\" width=\"100%\"><tr>";
   int count = oneDs.Tables[0].Rows.Count;
   //这里控制两列输出
   for(int rb = 0; rb < count;rb=rb+2)
   {
    strFirstMenu += "<td><a href=topicList.aspx?c="+oneDs.Tables[0].Rows[rb][0].ToString()+">"+oneDs.Tables[0].Rows[rb][1].ToString()+"</a></td>";
    if(rb+1==count){break;}
    strFirstMenu += "<td><a href=topicList.aspx?c="+oneDs.Tables[0].Rows[rb+1][0].ToString()+">"+oneDs.Tables[0].Rows[rb+1][1].ToString()+"</a></td>";
    strFirstMenu += "</tr><tr>";
    strFirstMenu += "<td>"+SecondMenu(oneDs.Tables[0].Rows[rb][0].ToString())+"</td>";
    strFirstMenu += "<td>"+SecondMenu(oneDs.Tables[0].Rows[rb+1][0].ToString())+"</td>";
    strFirstMenu += "</tr><tr>";
   }
   oneDs.Dispose();
   string FirstMenu = begin+strFirstMenu+"</tr></table>";
   return FirstMenu;

  }

posted on 2006-09-10 11:40  aliketen  阅读(380)  评论(0)    收藏  举报

导航