2013-01-25 113 views
0

我有一个动态的Listview,它使用一对多关系绑定到三个不同的表,即一个表行可能在其他表中包含很多行。当我运行我的应用程序时,我得到这个输出。 original output如何在列表视图中对一行值进行分组

但我想获得这种格式的Listview,虽然这个图像已经使用Photshop进行编辑。

Edited using Photoshop

这是ListviewHTML

<asp:ListView runat="server" ID="LV_ViewQuestion" DataKeyNames="UID, Question_ID"> 
       <EmptyDataTemplate> 
        <table id="Table1" runat="server" style=""> 
         <tr> 
          <td>No Surveys.</td> 
         </tr> 
        </table> 
       </EmptyDataTemplate> 
       <ItemTemplate> 
        <tr style=""> 
         <td> 
          <asp:Label ID="SURVEY_TYPELabel" runat="server" Text='<%# Eval("Survey_Type")%>' /> 
         </td> 
         <td> 
          <asp:Label ID="SURVEY_TITLELabel" runat="server" Text='<%# Eval("Survey_Title") %>' /> 
         </td> 
         <td> 
          <asp:Label ID="Question_TextLabel" runat="server" Text='<%# Eval("Question_Text")%>' /> 
         </td> 
         <td> 
          <asp:Label ID="Label2" runat="server" Text='<%# Eval("Option_Text")%>' /> 
         </td> 
         <td> 
          <asp:LinkButton runat="server" ID="lb_DelQuestion" Text="Delete" CommandArgument='<%# Eval("Question_ID")%>' CommandName="XDelQuestion" CssClass="GeneralInput" />&nbsp; 
          <asp:LinkButton runat="server" ID="lb_AddMoreQuest" Text="Add Question" CommandArgument='<%# Eval("UID")%>' CommandName="XAddAnotQuestion" CssClass="GeneralInput" />&nbsp; 
          <asp:LinkButton runat="server" ID="lb_Publish" Text="Publish" CommandArgument='<%# Eval("UID")%>' CommandName="XPublishSurvey" CssClass="GeneralInput" /> 

         </td> 
        </tr> 
       </ItemTemplate> 
       <LayoutTemplate> 
        <table id="Table2" runat="server"> 
         <tr id="Tr1" runat="server"> 
          <td id="Td1" runat="server"> 
           <table id="itemPlaceholderContainer" runat="server" class="nobordered" style="width: 580px;"> 
            <tr id="Tr2" runat="server" style=""> 
             <th id="Th1" runat="server">Type</th> 
             <th id="Th2" runat="server">Title</th> 
             <th id="Th6" runat="server">Question</th> 
             <th id="Th4" runat="server">Options</th> 
             <th id="Th3" runat="server" style="width: 200px;">Actions</th> 
            </tr> 
            <tr id="itemPlaceholder" runat="server"> 
            </tr> 
           </table> 
          </td> 
         </tr> 
         <tr id="Tr3" runat="server"> 
          <td id="Td2" runat="server" style=""> 
           <asp:DataPager ID="DataPager1" runat="server"> 
            <Fields> 
             <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" ButtonCssClass="GeneralButton" /> 
            </Fields> 
           </asp:DataPager> 
          </td> 
         </tr> 
        </table> 
       </LayoutTemplate> 
      </asp:ListView> 

回答

1

可以完成这个隐藏在细胞中ItemDataBound事件ListView的。您的代码应该是这样的:

先在自己的页面中添加三个全球性

string type = string.Empty; 
    string title = string.Empty; 
    string question = string.Empty; 

然后OnItemDataBound事件添加到您的列表视图

protected void LV_ViewQuestion_ItemDataBound(object sender, ListViewItemEventArgs e) 
{ 
    if (e.Item.ItemType == ListViewItemType.DataItem) 
    { 
     Label SURVEY_TYPELabel = (Label)e.Item.FindControl("SURVEY_TYPELabel");     
     Label SURVEY_TITLELabel = (Label)e.Item.FindControl("SURVEY_TITLELabel");     
     Label Question_TextLabel = (Label)e.Item.FindControl("Question_TextLabel");     

     if (SURVEY_TYPELabel.Text == type && SURVEY_TITLELabel == title && 
      Question_TextLabel == question) 
     { 
      SURVEY_TYPELabel.Visible = false; 
      SURVEY_TITLELabel.Visible = false; 
      Question_TextLabel.Visible = false;   
      // Do the same for all the other control in cells you need to hide 
     } 
     else 
     { 
      type = SURVEY_TYPELabel.Text; 
      title = SURVEY_TITLELabel.Text; 
      question = Question_TextLabel.Text; 
     } 
    } 

} 
+0

完美!欢呼和感谢。 – Sheery

相关问题