我用下面的代码为Repeater作分行事件,就是到7列后就分一行,但有一些在分的时候却出现了一行不够7列的问题,想知道如何解决?
protected int ii = 1;
    protected void repsitelist_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (ii % 7 == 0)
        {
            e.Item.Controls.Add(new LiteralControl("</tr><tr>"));
        }
        ii++;
    }

解决方案 »

  1.   

    跟踪一下你的代码
    用x符号标识一下你的生成结果给大伙看看x x x x x x x
    x x x
      

  2.   

    aspx代码也帖出来看看,看看能生成什么样的HTML
      

  3.   


    这样 protected void repsitelist_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((ii+1) % 7 == 0)
            {
                e.Item.Controls.Add(new LiteralControl("</td></tr><tr>"));
            }
            ii++;
        }
      

  4.   

    楼主绑定控件的外围html没提供,很难发现问题...
      

  5.   

    在ItemTemplate 里合适的位置
    <asp:Literal id="br" Visiable="false" runat="server" Text="<br />"></asp:Literal>然后在
    protected void repsitelist_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((ii+1) % 7 == 0)
            {
                Literal t = e.Item.FindControl("") as Literal;
                t.Visiable = true;
            }
            ii++;
        }
      

  6.   

    已经解决了,用的是datalist控件