我有一个GridView,我需要做过滤器,在日期和时间之间显示数据。
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="ExportDataGrid._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<style type="text/css">
#Select1
{
width: 109px;
}
#Select2
{
width: 109px;
}
</style>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to ASP.NET!
</h2>
<p>
To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
</p>
<p>
DataGrid here</p>
<p>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value=" 06:00:00 PM"></asp:ListItem>
<asp:ListItem Value=" 06:00:00 AM"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem Value=" 06:00:00 PM"></asp:ListItem>
<asp:ListItem Value=" 06:00:00 AM"></asp:ListItem>
</asp:DropDownList>
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<asp:Calendar ID="Calendar2" runat="server"></asp:Calendar>
</p>
<p>
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display.">
<Columns>
<asp:BoundField DataField="BatchId" HeaderText="BatchId"
SortExpression="BatchId" />
<asp:BoundField DataField="IncTank" HeaderText="IncTank"
SortExpression="IncTank" />
<asp:BoundField DataField="MoblieTank" HeaderText="MoblieTank"
SortExpression="MoblieTank" />
<asp:BoundField DataField="Recipe" HeaderText="Recipe"
SortExpression="Recipe" />
<asp:BoundField DataField="TransferStart" HeaderText="TransferStart"
SortExpression="TransferStart" />
<asp:BoundField DataField="TransferEnd" HeaderText="TransferEnd"
SortExpression="TransferEnd" />
<asp:BoundField DataField="TransferVol" HeaderText="TransferVol"
SortExpression="TransferVol" />
<asp:BoundField DataField="Operator" HeaderText="Operator"
SortExpression="Operator" />
<asp:BoundField DataField="Vessel" HeaderText="Vessel"
SortExpression="Vessel" />
<asp:BoundField DataField="WorkOrder" HeaderText="WorkOrder"
SortExpression="WorkOrder" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DB_user614ConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:DB_user614ConnectionString1.ProviderName %>"
SelectCommand="SELECT [BatchId], [IncTank], [MoblieTank], [Recipe], [TransferStart], [TransferEnd], [TransferVol], [Operator], [Vessel], [WorkOrder] FROM [MoblieFilling] WHERE [TransferStart] BETWEEN @TransferStart+@TimeStart AND @TransferEnd+@TimeEnd ">
<SelectParameters>
<asp:ControlParameter ControlID="Calendar1" DefaultValue="9/9/2011 2:30:30 PM" Name="TransferStart" />
<asp:ControlParameter ControlID="Calendar2" DefaultValue="9/9/2012 2:30:30 PM" Name="TransferEnd" />
<asp:ControlParameter ControlID="DropDownList1" Name="TimeStart" Type=DateTime DefaultValue="00:00:00" />
<asp:ControlParameter ControlID="DropDownList2" Name="TimeEnd" Type=DateTime DefaultValue="00:00:00" />
</SelectParameters>
</asp:SqlDataSource>
</p>
<p>
You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409"
title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
</p>
</asp:Content>
但这不起作用。我应该如何使用DropList选择合适的时间?宣言好吗?或者应该是不同的?
答案 0 :(得分:0)
您可以将AutoPostBack="true" and OnSelectIndexChanged="DropDownList_OnSelectIndexChanged"
添加到下拉列表中。
void DropDownList_OnSelectIndexChanged(Object sender, EventArgs e)
{
var filter = DropDownList1.SelectedValue;
//Request your data with citeria
//Re-bind your GridView
}