0

I have a dynamic Listview which is bind to three different tables with one to many relations i.e. one table row may contain many rows in other table. When i run my application i get this output. original output

But i want to get Listview in this format although this image has been edited using Photshop.

Edited using Photoshop

Here is Listview HTML.

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

1

You can accomplish this hiding the cells in the ItemDataBound event of the ListView. Your code should look like this:

first add three global properties in your page

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

Then add the OnItemDataBound event to your list view

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

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.