显示在GridView

问题描述:

重复的项目我都绑定到看起来像这样一些XML数据的GridView控件:显示在GridView

<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> 

在某些情况下,虽然,栏3点是不存在的。

我想呈现类似:

<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> 

如何Repeater控件被内部使用的GridView控件的,或者是有没有更好的方式来做到这一点?谢谢。

这看起来像一个中继器或datalist可以发射的HTML,没有gridvew。

如果你使用gridview,你会在模板字段的itemtemplate中放置一个中继器。你必须将某些东西绑定到gridview,这样它才能为中继器显示一行。

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

我认为一个中继器会自己做你想做的。

+0

如果我把一个Repeater放在TemplateField中,我怎样才能将它的数据源设置为当前列(第1,2列和[有时] 3)? – Bullines 2009-09-09 00:57:25

+0

你可以在一个文字中使用,但我不确定这是做这件事的最好方法。用一个中继器替换gridview是一个大问题?中继器比gridview更简单,重量更轻,速度更快。 – Steve 2009-09-09 15:57:14

还有一个问题,你显示的HTML,因为你预计输出。您不会使用与您的列标题<th>匹配的<td>删除行中的任何列。

你应该输出类似:

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

史蒂夫是正确的,你可以用一个中继实现这一目标。只需声明一个标题模板来保存开始表标记和标题行,用于保存表格结束标记的页脚模板以及用于输出,猜测项目行的项目模板。

你也可以尝试使用称为xsl样式表的somthing来使用xml转换。你加载你的XML,应用转换,并嘿presto很好格式化的HTML。尝试谷歌搜索一些例子。如果你没有运气,我会在有更多时间的情况下再次回到这里,然后举个例子。