Is it possible to output only the first instance of a value stored in a data table?
My example is this = I have a datatable wherein each row contains the name of a month. The table is ordered by month, in ascending order. I want to output the name of the month only on its first occurence in the table – if there are five entries with the month January, the text ‘January’ only needs be output once.
I’m using a repeater – code below. The value in Month should only change if it is different to the value in the previous row.
<asp:Repeater ID="rptEvents" runat="server">
<ItemTemplate>
<h5><%#Eval("Month")%></h5>
<p>
<strong><asp:HyperLink ID="hlEvents" runat="server" Text='<%#Eval("Title") %>' NavigateUrl='<%#Eval("QuickLink") %>'></asp:HyperLink></strong><br />
<%#Eval("Date") %><br />
<%#Eval("Description") %>
</p>
</ItemTemplate>
</asp:Repeater>
Well, I’m not sure but how about doing it on the db-side?
SELECT MIN(DISTNCT Month), Title, QuickLink FROM Title, QuickLink
UPDATE:
Seems like I was misunderstood. How about using a method?
And in code-behind, define a class-scope variable to hold the previous month name and compare it to the current month name in your method: