代码之家  ›  专栏  ›  技术社区  ›  Bullines

在网格视图中显示重复项

  •  1
  • Bullines  · 技术社区  · 17 年前

    <Root>
        <Column1>
            <Item1 type="l1style">Item 1</Item1>
            <Item2 type="l2style">Item 2</Item2>
            <Item3 type="l3style">Item 3</Item3>
        </Column1>
    
        <Column2>
            <Item4 type="l1style">Item 4</Item4>
            <Item5 type="l2style">Item 5</Item5>
        </Column2>
    
        <Column3>
            <Item6 type="l1style">Item 6</Item6>
            <Item7 type="l2style">Item 7</Item7>
        </Column3>
    </Root>
    

    不过,在某些情况下,Column3节点不存在。

    <table>
        <thead>
            <tr>
                <th scope="col">Column1</th>
                <th scope="col">Column2</th>
                <th scope="col">Column3</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>                
                    <ul>
                        <li class="l1style">Item 1</li>
                        <li class="l2style">Item 2</li>
                        <li class="l3style">Item 3</li>
                    </ul>
                </td>
                <td>
                    <ul>
                        <li class="l1style">Item 4</li>
                        <li class="l2style">Item 5</li>
                    </ul>
                </td>
                <td>
                    <ul>
                        <li class="l1style">Item 6</li>
                        <li class="l2style">Item 7</li>
                    </ul>
                </td>
            </tr>
        </tbody>
    </table>
    

    如何在GridView中使用Repeater控件,或者是否有更好的方法来实现这一点?谢谢。

    2 回复  |  直到 17 年前
        1
  •  1
  •   Steve    17 年前

    这看起来像是可以由转发器或数据列表发出的html,而不需要gridvew。

    如果您使用gridview,那么应该在templatefield列的itemtemplate中放置一个repeater。您必须将某些内容绑定到gridview,以便它呈现一行供repeater显示。

    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                Your Repeater
    

    我想一个中继器就能做你想做的事。

        2
  •  1
  •   user2279306    17 年前

    您所显示的html作为预期输出也有一个问题。您不需要使用 <td> <th> .

    您应该输出如下内容:

    <table>
     <tr>
       <th> ... </th>
       <th> ... </th>
       <th> ... </th>
     </tr>
     <tr>
       <td> ... </td>
       <td> ... </td>
       <td> ... </td>
     </tr>
    ...
    

    您还可以尝试使用一种称为xsl样式表的东西来进行xml转换。您可以加载xml,应用转换,然后重新格式化html。试着在谷歌上搜索一些例子。等我有时间的时候我会再来这里,如果你运气不好的话,我会给你举个例子。

    推荐文章