2017-10-18 100 views
0

我有一個搜索按鈕和兩個文本框作爲日期時間選擇器。我能做些什麼來顯示特定日期間隔內的所有記錄?我是編程新手。如何在兩個日期之間顯示GridView中的記錄

<%@ Page Title="Report" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="Report.aspx.vb" 
    Inherits="Report" %> 
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent"> 

<asp:GridView ID="gvItems" runat="server" AutoGenerateColumns ="false"> 
     <Columns> 
      <asp:BoundField HeaderText="Part Number" DataField="Part_Number" readonly="true" ></asp:BoundField> 
      <asp:BoundField HeaderText="Last Inventory" DataField="Last_Inv" readonly="true" ></asp:BoundField> 
      <asp:BoundField HeaderText="Last Quantity" DataField="Last_Qty" readonly="true" ></asp:BoundField> 
      <asp:BoundField HeaderText="Inventory Today" DataField="Today_Inv" readonly="true" ></asp:BoundField> 
      <asp:BoundField HeaderText="Today's Quantity" DataField="Today_Qty" readonly="true" ></asp:BoundField> 

     </Columns> 
    </asp:GridView> 

<br /> 
<br /> 

<div class ="container" > 
    <div class="input-group class col-sm-3 col-md-6"> 
     <asp:Button ID="btnSearch" runat="server" Text="Search" /> 
     <asp:TextBox ID="txtbxSearch1" runat="server" TextMode ="Date" Width="205px"></asp:TextBox>  
     <asp:TextBox ID="txtbxSearch2" runat="server" TextMode ="Date" Width="205px"></asp:TextBox> 
    </div> <br /> <br /> 
</div> 
<br /> 
<br /> 

+1

那麼,過濾在'btnSearch.Click'的'GridView'的數據源 –

回答

0
Imports System.Data 


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) 
     Dim ds As DataSet = New DataSet 
     ds.Tables.Add(New DataTable) 
     ds.Tables(0).Columns.AddRange(New DataColumn() {New DataColumn("Id", GetType(System.Int32)), New DataColumn("Name", GetType(System.String)), New DataColumn("DOB", GetType(DateTime))}) 
     ds.Tables(0).Rows.Add(1, "John Hammond", "12/12/1996") 
     ds.Tables(0).Rows.Add(2, "Mudassar Khan", "11/16/1995") 
     ds.Tables(0).Rows.Add(3, "Suzanne Mathews", "10/20/1997") 
     ds.Tables(0).Rows.Add(4, "Robert Schidner", "09/22/1991") 
     Dim dt2 As DataTable = New DataTable 
     dt2 = ds.Tables(0).Select.Where(() => { }, ((Convert.ToDateTime(p("DOB")) >= Convert.ToDateTime("12/12/1996")) _ 
         AndAlso (Convert.ToDateTime(p("DOB")) >= Convert.ToDateTime("12/12/1996")))).CopyToDataTable 
     GridView1.DataSource = dt2 
     GridView1.DataBind 
    End Sub 

另外,下面這個環節應該讓你在正確的方向前進。

https://forums.asp.net/t/2041882.aspx?GridView+Filter+between+2+dates

相關問題