我在我的asp.net项目中使用了Gridview,并启用了如下的soring功能。
<asp:GridView ID="Imp_Report" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
Font-Bold="False" Font-Names="Verdana"
ForeColor="#333333" GridLines="None" HorizontalAlign="Left" PageSize="20"
style="margin-right: 288px" Width="900px"
onselectedindexchanged="Imp_Report_SelectedIndexChanged"
DataSourceID="ReportConn">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Report_No" HeaderText="Report_No"
InsertVisible="False" ReadOnly="True" SortExpression="Report_No" />
<asp:BoundField DataField="Project_Name" HeaderText="Project_Name"
SortExpression="Project_Name" />
<asp:BoundField DataField="Start_Time" HeaderText="Start_Time"
SortExpression="Start_Time" />
<asp:BoundField DataField="Duration (In Min)" HeaderText="Duration (In Min)"
ReadOnly="True" SortExpression="Duration (In Min)" />
<asp:BoundField DataField="Engineer_Name" HeaderText="Engineer_Name"
SortExpression="Engineer_Name" />
<asp:BoundField DataField="Lead_Name" HeaderText="Lead_Name"
SortExpression="Lead_Name" />
<asp:BoundField DataField="Overview" HeaderText="Overview"
SortExpression="Overview" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:SqlDataSource ID="ReportConn" runat="server"
ConnectionString="<%$ ConnectionStrings:GNSConcallReportsConnectionString %>"
SelectCommand="SELECT [Report_No], [Project_Name], [Start_Time], DATEDIFF(minute,[Start_Time],[End_Time]) as 'Duration (In Min)', [Engineer_Name], [Lead_Name], [Overview] FROM [ConcallReports]">
</asp:SqlDataSource>
但是我根据我在下面的表单中使用的过滤器动态更改选择条件。
ReportConn.SelectCommand = "SELECT [Report_No], [Project_Name], [Start_Time], DATEDIFF(minute,[Start_Time],[End_Time]) as 'Duration (In Min)', [Engineer_Name], [Lead_Name], [Overview] FROM [ConcallReports] where "+query; //Here query indicates the filter that was used
ReportConn.DataBind();
除了排序外,上述所有工作正常。
当我进行排序时,正在进行排序。但是我丢失了过滤后的值,我得到了在页面开头加载的数据。
请帮我解决问题