title: data is not sorted in gridview when being inserted
body: <p>my gridview picks records form database, it's fine but problem is that when new record is updated than it is not necessarily added at the end of all records in gridview, it could appear 2nd last, in middle, at start even. I mean it doesn't appear sorted or in sequence.</p>
  
  <p>.cs</p>
  
  <pre><code>protected void btnSearch_Click1(object sender, EventArgs e)
      {
          SqlDataSourceETTVehicleLed.SelectParameters["RegistrationNo"].DefaultValue = txtboxVehicleNo.Text;
          gvVehicleLedger.DataBind();
          gvVehicleLedger.Visible = true;
  
      }
  </code></pre>
  
  <p>.aspx</p>
  
  <pre><code>&lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
          &lt;asp:Button ID="btnHome" runat="server" Text="Home" CssClass="button" Width="7%" OnClick="btnHome_Click" /&gt;
      &lt;/div&gt;
      &lt;br /&gt;
      &lt;div&gt;
         &lt;asp:Panel ID="pnlInput" runat="server" DefaultButton="btnSearch"&gt;
          &lt;asp:TextBox ID="txtboxVehicleNo" runat="server"&gt;&lt;/asp:TextBox&gt; &amp;nbsp
          &lt;asp:Button ID="btnSearch" Text="Search" Width="9%" CssClass="button" runat="server" OnClick="btnSearch_Click1" /&gt;
         &lt;/asp:Panel&gt;
      &lt;/div&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;div&gt;
          &lt;asp:GridView ID="gvVehicleLedger" ShowHeaderWhenEmpty="True" runat="server" CellPadding="7" DataSourceID="SqlDataSourceETTVehicleLed" ForeColor="#333333" GridLines="None" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="Vehicle No" Width="100%" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px"&gt;
              &lt;AlternatingRowStyle BackColor="White" /&gt;
              &lt;Columns&gt;
                  &lt;asp:BoundField DataField="Vehicle No" HeaderText="Vehicle No" ReadOnly="True" SortExpression="Vehicle No" &gt;
                  &lt;HeaderStyle HorizontalAlign="Left" Wrap="False" /&gt;
                  &lt;ItemStyle HorizontalAlign="Left" /&gt;
                  &lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="Transaction Date" HeaderText="Transaction Date" SortExpression="Transaction Date"&gt;
                  &lt;HeaderStyle HorizontalAlign="Left" /&gt;
                  &lt;ItemStyle HorizontalAlign="Left" Wrap="False" /&gt;
                  &lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="Engine Capacity" HeaderText="Engine Capacity" SortExpression="Engine Capacity" &gt;
                  &lt;HeaderStyle HorizontalAlign="Left" Wrap="False" /&gt;
                  &lt;ItemStyle HorizontalAlign="Left" Wrap="False" /&gt;
                  &lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" &gt;
                  &lt;HeaderStyle HorizontalAlign="Left" /&gt;
                  &lt;ItemStyle HorizontalAlign="Left" /&gt;
                  &lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" &gt;
                  &lt;HeaderStyle HorizontalAlign="Left" /&gt;
                  &lt;ItemStyle HorizontalAlign="Left" /&gt;
                  &lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="No Of Months" HeaderText="No Of Months" SortExpression="No Of Months" &gt;
                  &lt;HeaderStyle HorizontalAlign="Center" Wrap="False" /&gt;
                  &lt;ItemStyle HorizontalAlign="Center" /&gt;
                  &lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" &gt;
                  &lt;HeaderStyle HorizontalAlign="Right" /&gt;
                  &lt;ItemStyle HorizontalAlign="Right" /&gt;
                  &lt;/asp:BoundField&gt;
              &lt;/Columns&gt;
              &lt;EditRowStyle BackColor="#2461BF" /&gt;
              &lt;FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /&gt;
              &lt;HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /&gt;
              &lt;PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /&gt;
              &lt;RowStyle BackColor="#EFF3FB" /&gt;
              &lt;SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /&gt;
              &lt;SortedAscendingCellStyle BackColor="#F5F7FB" /&gt;
              &lt;SortedAscendingHeaderStyle BackColor="#6D95E1" /&gt;
              &lt;SortedDescendingCellStyle BackColor="#E9EBEF" /&gt;
              &lt;SortedDescendingHeaderStyle BackColor="#4870BE" /&gt;
              &lt;emptydatarowstyle backcolor="#eff3fb"
                forecolor="Red"/&gt;
              &lt;EmptyDataTemplate&gt;
                No Records Found 
              &lt;/EmptyDataTemplate&gt; 
          &lt;/asp:GridView&gt;
          &lt;asp:SqlDataSource ID="SqlDataSourceETTVehicleLed" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ETTConnectionStr %&gt;" SelectCommand="Vehicleledger" SelectCommandType="StoredProcedure"&gt;
              &lt;SelectParameters&gt;
                  &lt;asp:ControlParameter ControlID="txtboxVehicleNo" Name="RegistrationNo" PropertyName="Text" Type="String" /&gt;
              &lt;/SelectParameters&gt;
          &lt;/asp:SqlDataSource&gt;
      &lt;/div&gt;
  
      &lt;/form&gt;
  </code></pre>
  
  <p>Store Procedure:</p>
  
  <pre><code>ALTER procedure [dbo].[Vehicleledger]
  @RegistrationNo varchar(20)
  as
  
  begin
  
  SELECT dbo.Vehicle.RNo AS 'Vehicle No', dbo.TransactionTable.DateOfTransaction as 'Transaction Date', dbo.EngineCapacity.EngineCapcity as 'Engine Capacity', 
                 dbo.MainCategories.Name as 'Name', dbo.Categories.Description as 'Description', dbo.TransactionTable.NoOfMonth as 'No Of Months', dbo.TransactionTable.Amount as 'Amount'
  FROM  dbo.Categories INNER JOIN
                 dbo.MainCategories ON dbo.Categories.MainCategory_ID = dbo.MainCategories.CatID INNER JOIN
                 dbo.TransactionTable ON dbo.Categories.ID = dbo.TransactionTable.CategoryID INNER JOIN
                 dbo.EngineCapacity ON dbo.TransactionTable.EngineCapacityID = dbo.EngineCapacity.ID RIGHT OUTER JOIN
                 dbo.Vehicle ON dbo.TransactionTable.RNo = dbo.Vehicle.RNo
  where dbo.Vehicle.RNo=@RegistrationNo
  end
  </code></pre>