Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to display the name once and that particular name having values but i am getting the name repeatedly with the values. I am designing Online Examination system in c# asp.net in which Students Questions having Nested Repeaters. Outer Repeater is getting the Subject Topic Name and Inner Repeater is having Questions with options to select. My problem is Subject topic name is getting repeated with the questions that means first question is having topic name 'Auxiliary Verbs'. This topic name has 10 questions for this 10 questions i am getting Auxiliary Verbs 10 times that i don't require. How to achieve this please anybody answer me i will share you query i have used, Nested Repeater and coding part. Please have a look and give me appropriate solution for this problem.

What I have tried:

Sql Query Select Command:
string query = "SELECT DISTINCT SubjectCategory, QuestionNumber FROM QuestionPaper";


Nested Repeater Aspx Page:
<asp:Repeater ID="RptrSubjectCategory" OnItemDataBound="RptrSubjectCategory_ItemDataBound" runat="server">
    <HeaderTemplate>
        <table style="min-height:300px;width:100%;">
    </HeaderTemplate>
    <SeparatorTemplate>
        <tr><td><br /></td></tr>
    </SeparatorTemplate>
    <ItemTemplate>
        <tr style="text-align:left;">
            <th>Topic: <%# DataBinder.Eval(Container.DataItem,"SubjectCategory") %></th>
        </tr>

        <%-- Repeater Questions With Choices --%>
        <asp:Repeater ID="RptrQuestionsAdnChoices" OnItemDataBound="RptrQuestionsAdnChoices_ItemDataBound" runat="server" DataSource='<%# ((System.Data.DataRowView)Container.DataItem).Row.GetChildRows("myRelation") %>'>
            <ItemTemplate>
                <tr>
                    <td style="padding:5px;">
                        <asp:Label ID="lblQuestionNuumber" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "[\"QuestionNumber\"]") %>'></asp:Label>
                          <%# DataBinder.Eval(Container.DataItem, "[\"Question\"]") %>
                    </td>
                </tr>
                <tr>
                    <td style="padding:5px;">
                        <asp:RadioButton ID="rb1" runat="server" />
                        A) <asp:Label ID="lblChoiceA" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "[\"ChoiceA\"]") %>' AssociatedControlID="rb1"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td style="padding:5px;">
                        <asp:RadioButton ID="rb2" runat="server" />
                        B) <asp:Label ID="lblChoiceB" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "[\"ChoiceB\"]") %>' AssociatedControlID="rb2"></asp:Label>                                                                
                    </td>
                </tr>
                <tr>
                    <td style="padding:5px;">
                        <asp:RadioButton ID="rb3" runat="server" />
                        C) <asp:Label ID="lblChoiceC" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "[\"ChoiceC\"]") %>' AssociatedControlID="rb3"></asp:Label>                                                             
                    </td>
                </tr>
                <tr>
                    <td style="padding:5px;">
                        <asp:RadioButton ID="rb4" runat="server" />
                        D) <asp:Label ID="lblChoiceD" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "[\"ChoiceD\"]") %>' AssociatedControlID="rb4"></asp:Label>                                                       
                    </td>
                </tr>
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
    <FooterTemplate>
        <tr style="text-align:left;">
            <td style="padding:5px;">
                <asp:LinkButton ID="LnkBtnSubmit" runat="server" CssClass="btn btn-success">class="fa fa-arrow-circle-right fa-lg">Finish</asp:LinkButton>
            </td>
        </tr>
        </table>
    </FooterTemplate>
</asp:Repeater>
Posted
Updated 15-Nov-18 22:24pm

1 solution

Quote:
This topic name has 10 questions for this 10 questions i am getting Auxiliary Verbs 10 times that i don't require.

The problem with your query is that you have included the QuestionNumber column. It is unlikely that you actually want the question number so just leave it out
SQL
SELECT DISTINCT SubjectCategory FROM QuestionPaper
Alternatively you can use GROUP BY and return something meaningful such as the number of questions in each category e.g.
SQL
SELECT SubjectCategory, COUNT(QuestionNumber) as NoOfQuestions FROM QuestionPaper GROUP BY SubjectCategory
 
Share this answer
 
Comments
Member 8583441 19-Nov-18 4:09am    
Sorry for the late reply, i will check it and let you know sir
Member 8583441 19-Nov-18 4:23am    
Getting error: This constraint cannot be enabled as not all values have corresponding parent values. at System.Data.ConstraintCollection.AddForeignKeyConstraint(ForeignKeyConstraint constraint) at System.Data.ConstraintCollection.Add(Constraint constraint, Boolean addUniqueWhenAddingForeign) at System.Data.DataRelationCollection.DataSetRelationCollection.AddCore(DataRelation relation) at System.Data.DataRelationCollection.Add(DataRelation relation) at System.Data.DataRelationCollection.Add(String name, DataColumn parentColumn, DataColumn childColumn)
CHill60 19-Nov-18 7:42am    
I'm not adding any foreign keys in my suggested approach so it is your data that is at fault. You must have a NULL SubjectCategory?
Member 8583441 19-Nov-18 4:25am    
If i use this statement "SELECT SubjectCategory, COUNT(QuestionNumber) as NoOfQuestions FROM QuestionPaper GROUP BY SubjectCategory" the above error occurs

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900