日期:2014-05-18  浏览次数:20416 次

100分请大家帮我看下为什么我这个for循环只能一次,是语法错误吗?
WebService shuju = new WebService();

  DataTable table;
  protected void Page_Load(object sender, EventArgs e)
  {
  if (!Page.IsPostBack)
  {
  catrory();
  }
  }

 
  private void catrory()
  {
   
  string sql1 = "select catname,catid from sc_cat where fid=0 ";
  table = shuju.ExcuteSelect(sql1);
  StringBuilder cat = new StringBuilder();
   
  cat.Append("<div class=\"padtb8\">");
  for (int i = 0; i < table.Rows.Count; i++)
  {

  cat.Append("<div class=\"f fblod\" id=\"sgc" + table.Rows[i]["catid"].ToString() + "\" onclick=\"w('gc" + table.Rows[i]["catid"].ToString() + "')\">");
  cat.Append("<a href=\"product_lm" + table.Rows[i]["catid"].ToString() + ".html\">");
  cat.Append("" + table.Rows[i]["catname"].ToString() + "</a></div>");
  cat.Append("<div class=\"ps\" id=\"gc" + table.Rows[i]["catid"].ToString() + "\" style=\"display:block\">");

  table = shuju.ExcuteSelect("select catname,catid from sc_cat where fid=" + table.Rows[i]["catid"].ToString() + " ");
   
  for (int n = 0; n <table.Rows.Count; n++)
  {
  cat.Append("<div id=\"sfgc" + table.Rows[n]["catid"].ToString() + "\" class=\"f\" onclick=\"k('fgc" + table.Rows[n]["catid"].ToString() + "')\">");
  cat.Append("" + table.Rows[n]["catname"].ToString() + "</div>");
  cat.Append("<div class=\"ps\" id=\"fgc" + table.Rows[n]["catid"].ToString() + "\">");

  table = shuju.ExcuteSelect("select catname,catid from sc_cat where fid=" + table.Rows[n]["catid"].ToString() + " ");
  if (table.Rows.Count > 0)
  {
  for (int m = 0; m < table.Rows.Count; m++)
  {
  cat.Append("<div class=\"b\">");
  cat.Append("<a href=\"product_lm" + table.Rows[m]["catid"].ToString() + ".html\">");
  cat.Append("" + table.Rows[m]["catname"].ToString() + "</a></div>");
  }

  }
  cat.Append("</div>");
  }
  cat.Append("</div>");
  }
  cat.Append("</div>");
  this.catr.Text = cat.ToString();

   
  }


------解决方案--------------------
table = shuju.ExcuteSelect("select catname,catid from sc_cat where fid=" + table.Rows[i]["catid"].ToString() + " "); 

不要在循环内部改变循环的终止条件.
table = shuju.ExcuteSelect("select catname,catid from sc_cat where fid=" + table.Rows[i]["catid"].ToString(