我的gridview选择记录表格数据库,这很好,但问题是,当新记录更新时,它不一定会添加到gridview中所有记录的末尾,它可能会显示在最后,中间,开始甚至。我的意思是它没有按顺序或按顺序出现。
的.cs
protected void btnSearch_Click1(object sender, EventArgs e)
{
SqlDataSourceETTVehicleLed.SelectParameters["RegistrationNo"].DefaultValue = txtboxVehicleNo.Text;
gvVehicleLedger.DataBind();
gvVehicleLedger.Visible = true;
}
的.aspx
<form id="form1" runat="server">
<div>
<asp:Button ID="btnHome" runat="server" Text="Home" CssClass="button" Width="7%" OnClick="btnHome_Click" />
</div>
<br />
<div>
<asp:Panel ID="pnlInput" runat="server" DefaultButton="btnSearch">
<asp:TextBox ID="txtboxVehicleNo" runat="server"></asp:TextBox>  
<asp:Button ID="btnSearch" Text="Search" Width="9%" CssClass="button" runat="server" OnClick="btnSearch_Click1" />
</asp:Panel>
</div>
<br />
<br />
<div>
<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">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Vehicle No" HeaderText="Vehicle No" ReadOnly="True" SortExpression="Vehicle No" >
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Transaction Date" HeaderText="Transaction Date" SortExpression="Transaction Date">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Engine Capacity" HeaderText="Engine Capacity" SortExpression="Engine Capacity" >
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
<ItemStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="No Of Months" HeaderText="No Of Months" SortExpression="No Of Months" >
<HeaderStyle HorizontalAlign="Center" Wrap="False" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" >
<HeaderStyle HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
<emptydatarowstyle backcolor="#eff3fb"
forecolor="Red"/>
<EmptyDataTemplate>
No Records Found
</EmptyDataTemplate>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceETTVehicleLed" runat="server" ConnectionString="<%$ ConnectionStrings:ETTConnectionStr %>" SelectCommand="Vehicleledger" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="txtboxVehicleNo" Name="RegistrationNo" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
存储过程:
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
答案 0 :(得分:0)
您需要在查询结束时提供ORDER BY。在不知道您的表架构的情况下,我只能猜测您应该订购什么。但是,如果您确实有一个自动编号的主键,我建议使用它来按顺序排序。