如何在listview中创建rowspan?

时间:2017-01-12 13:51:37

标签: c# html asp.net listview

我有一个listview(不是gridview),我想把相同的结果放在一个单元格中 我不能像在gridview中那样使用rowspan来制作它,因为listview没有这种方法。
我现在拥有的:

FullName  | LgotName | 
------------------------                           
John      |First     |                        
John      |Second    |                          
John      |Third     |    

我想拥有什么

FullName  | LgotName | 
------------------------                           
John      |First     |
          |----------|            
          |Second    | 
          |----------| 
          |Third     | 
------------------------ (this is end of John row)

我的代码:

 <asp:ListView ID="ListView1" runat="server"... >
                <LayoutTemplate>
                    <div class="outerContainer">
                        <table id="docnewTable">
                            <thead>
                                <tr>
                                    <th>Full Name</th>
                                    <th>LgotName</th>
                                <th></th>
                                    <th></th>
                                </tr>
                            </thead>

                            <tbody runat="server" id="itemPlaceholder"></tbody>
                        </table>
                    </div>
                </LayoutTemplate>
                <ItemTemplate>
                    <tr>
                        <td><%# Item.fam_v %></td>
                        <td><%# Item.im_v %></td>
                        <td>
                            <asp:Button ID="ChangeDocBtn" runat="server"  />
                        </td>
                        <td>
                            <asp:Button ID="DeleteDocBtn" runat="server" Text="Delete  />
      </td>
     </tr>
                </ItemTemplate>
      </asp:ListView>

我想到循环 - 选择一个值,然后跳过1,但效果不是很好。

我使用Asp.net,EF,linq

我在c#中的选择方法:
            我

Enumerable<FinalDoc> fidn = from post in repository.doctors
                                             join meta in repository.DoctorsLG on post.pcod equals meta.pcod
                                             join thir in repository.SP_lgota on meta.idGK equals thir.C_LGT
                                             where post.actual == 1                                                  select new FinalDoc
                                             {
                                                 mcod = post.mcod,
                                                 pcod = post.pcod,
                                                 c_ogrn = post.c_ogrn,
                                                 fam_v = post.fam_v,
                                                 im_v = post.im_v,
                                                 ot_v = post.ot_v,
                                                 idGK = meta.idGK,
                                                    LgotName = thir.LgotName
                                             }

请仔细阅读。  如何将我的结果组合成rowpan?
如果我只是写rowspan我将添加SAMPLE RESULTS,我需要添加如下:value with index [0],value with index [1],value with index [2]。

1 个答案:

答案 0 :(得分:1)

尝试以下内容

    <asp:ListView ID="ListView1" runat="server"... >
                        <LayoutTemplate>
                            <div class="outerContainer">
                                <table id="docnewTable">
                                    <thead>
                                        <tr>
                                            <th>Full Name</th>
                                            <th>LgotName</th>
                                        <th></th>
                                            <th></th>
                                        </tr>
                                    </thead>

                                    <tbody runat="server" id="itemPlaceholder"></tbody>
                                </table>
                            </div>
                        </LayoutTemplate>
                        <ItemTemplate>
                            <tr>
                                <td><%# Item.fam_v %></td>
                         <td>       
        // Place new Listview here like
       <table> <asp:ListView ID="ListView2" runat="server">
<tr>
<td><%# Item.im_v %></td>
</tr>
</asp:ListView>
</table>
</td>

                                <td>
                                    <asp:Button ID="ChangeDocBtn" runat="server"  />
                                </td>
                                <td>
                                    <asp:Button ID="DeleteDocBtn" runat="server" Text="Delete  />
              </td>
             </tr>
                        </ItemTemplate>
              </asp:ListView>

将数据绑定在ListView1的Itemdatabound事件上。