如何在两个日期之间在GridView中显示记录

时间:2017-10-18 07:50:47

标签: vb.net

我有一个搜索按钮和两个用作日期时间选择器的文本框。如何显示特定日期间隔内的所有记录?我是编程新手。

<%@ 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 个答案:

答案 0 :(得分: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