Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying records grouped by month and year in asp.net
    primarykey
    data
    text
    <p>I need to sort my records by date (month &amp; year) as displayed on my asp.net page;<br> Any ideas / suggestions would be helpful. </p> <p>This is the code I currently have</p> <pre><code> &lt;table width="40%" border="0" style="margin-left:auto; margin-right:auto;"&gt; &lt;tr&gt;&lt;td&gt;&lt;asp:Label ID="lblGridHeader" CssClass="TextFont" Text="" runat="server"&gt;&lt;/asp:Label&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="center"&gt; &lt;asp:GridView ID="gvInvoiceList" runat="server" AutoGenerateColumns="false" AllowSorting="true"&gt; &lt;columns&gt; &lt;asp:TemplateField ItemStyle-Width="10%" HeaderText="File Type"&gt; &lt;ItemTemplate&gt;&lt;asp:HyperLink ID="imgFileType" ImageUrl="images/Icon_Pdf.gif" NavigateUrl='&lt;%# SetNavigateUrl(Eval("Name")) %&gt;' runat="server"&gt;&lt;/asp:HyperLink&gt;&lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:boundfield datafield="Name" headertext="Invoice #"/&gt; &lt;asp:boundfield datafield="LastWriteTime" headertext="Date Modified"/&gt; &lt;/columns&gt; &lt;/asp:GridView&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p><strong>Code behind:</strong> </p> <pre><code> If files.Count &gt; 0 Then Dim DT As New DataTable() DT.Columns.Add(New DataColumn("Name", System.Type.GetType("System.String"))) DT.Columns.Add(New DataColumn("LastWriteTime", System.Type.GetType("System.String"))) Dim strCurrentMonth As String = "" For Each f As FileInfo In files If (MonthName(f.LastWriteTime.Month) &lt;&gt; strCurrentMonth) And (strCurrentMonth &lt;&gt; "") Then gvInvoiceList.DataSource = DT gvInvoiceList.DataBind() lblGridHeader.Text = MonthName(f.LastWriteTime.Month) &amp; " - " &amp; Year(f.LastWriteTime) Else lblGridHeader.Text = MonthName(f.LastWriteTime.Month) &amp; " - " &amp; Year(f.LastWriteTime) End If Dim Row1 As DataRow Row1 = DT.NewRow() Row1("Name") = f.Name Row1("LastWriteTime") = f.LastWriteTime DT.Rows.Add(Row1) strCurrentMonth = MonthName(f.LastWriteTime.Month) Next gvInvoiceList.DataSource = DT gvInvoiceList.DataBind() Else lblSummary.Text = "No data to show." End If </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload