Как использовать ключевое слово distinct в запрос SELECT, чтобы отобразить вложенные репитеры ASP.NET с#
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.
Что я уже пробовал:
Выберите Команду Запрос SQL :
string query = "SELECT DISTINCT SubjectCategory, QuestionNumber FROM QuestionPaper";
Вложенная Страница Aspx Ретранслятора:
<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">Finish</asp:LinkButton> </td> </tr> </table> </FooterTemplate> </asp:Repeater>