0

I have a aspGridView Control. I am only using it to display information and it does not allow the user to filter. I would like to preset the information where it displays it using a descending sort on the column read_date. Can I do this from the controllers settings?

<asp:GridView AllowPaging="true" runat="server" ID="gridRead" AutoGenerateColumns='false' BorderStyle="None" GridLines="None" HorizontalAlign="Center" Width="200px" PageSize="12" >


    <PagerSettings Visible="false" />
                    <Columns>
                    <asp:BoundField 
                        HeaderText="Date"  
                        HeaderStyle-HorizontalAlign="Left" 
                        DataField="read_date" 
                        Visible="true" 
                        DataFormatString="{0:d}"  
                        ItemStyle-HorizontalAlign="Left" 
                        HeaderStyle-ForeColor="#004C7E"
                        HeaderStyle-Font-Underline="true" 
                        ItemStyle-ForeColor="#004C7E"
                         ItemStyle-Font-Size="Medium"
                     />
                    <asp:BoundField  
                        HeaderText="Reading" 
                        HeaderStyle-HorizontalAlign="Left" 
                        DataField="reading" 
                        Visible="true"  
                        DataFormatString="{0:C}"  
                        ItemStyle-HorizontalAlign="Left" 
                        HeaderStyle-ForeColor="#004C7E"
                        HeaderStyle-Font-Underline="true" 
                        ItemStyle-ForeColor="#004C7E"
                        ItemStyle-Font-Size="Medium"
                        ItemStyle-CssClass="datagridStyle"
                    />

So I just want to display the grid with read_date descending. I am binding a DataSet to this grid. Thanks

Jaiesh_bhai
  • 1,778
  • 8
  • 26
  • 41
  • What does your data source look like? I.E. What kind of data source are you using. – MikeH Jan 16 '14 at 17:48
  • Just trigger the grid's OnSort event manually somewhere before you display the grid to the user. You can read more about this at [MSDN](http://msdn.microsoft.com/en-us/library/hwf94875.aspx) or here on [Stack Overflow](http://stackoverflow.com/a/702603/1751238). You will have to tweak the SO answer to fit your grid, but fairly simple. – Evan L Jan 16 '14 at 17:49
  • @MikeH Thank you for pointing that out. I am using DataBind on a DataSet that gets created from a SELECT Query returned from a sql stored procedure – Jaiesh_bhai Jan 16 '14 at 17:56
  • 1
    Can you set the "order by" command in the stored procedure? – MikeH Jan 16 '14 at 18:07
  • @MikeH I ended up doing this. Would you like to provide an answer so I can mark it as a solution. – Jaiesh_bhai Feb 03 '14 at 14:48

1 Answers1

2

Set the "order by" command in your stored procedure.

MikeH
  • 4,242
  • 1
  • 17
  • 32