C# ASP.NET网格视图中的排序问题
我在asp.net项目中使用Gridview,并且启用了如下所示的排序功能C# ASP.NET网格视图中的排序问题,c#,asp.net,sorting,gridview,C#,Asp.net,Sorting,Gridview,我在asp.net项目中使用Gridview,并且启用了如下所示的排序功能 <asp:GridView ID="Imp_Report" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" Font-Bold="False" Font-Names="Verdana" ForeColor="#333
<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();
除分拣外,上述各项工作正常
当我进行排序时,排序正在进行。但是我失去了过滤值,我得到了在页面开始加载的数据
请帮助我解决此问题您必须始终在页面加载时设置selectCommand,并且仅在更改查询时才在回发时进行数据绑定。如果您包括您调用它的位置(SelectCommand和databind),我可以告诉您如何实现它。但是,我不确定在哪里调用数据绑定函数。你能帮我更正我的代码吗?我在你的问题上看到的
ReportConn.DataBind()
,在哪里调用?(在页面加载?在按钮上单击?在哪里?)