2016-08-06 85 views
0

我使用asp.net gridview和ajax日历扩展。例如,用户选择像19/8/16这样的日期,那么它只会在gridview表中显示19/8/16的日期。但问题是我不知道什么代码隐藏和显示gridview。任何人都知道如何隐藏和显示gridview?如何隐藏并显示Gridview表格?

输出:

enter image description here

Asp.net代码:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ViewAppliedLeaveByDate.aspx.cs" Inherits="BookReservation.ViewLeave.ViewAppliedLeaveByDate" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" runat="server"> 
    <asp:ScriptManager ID="ScriptManager1" runat="server"> 
    </asp:ScriptManager> 

    <h3>View Leave Application By Start Date</h3> 
    <asp:Label ID="lblSearchStartDate" runat="server" CssClass="labelClass" Text="Search By Start Date:"></asp:Label> 
    <asp:TextBox ID="tbSearchStartDate" runat="server"></asp:TextBox> 
    <ajaxToolkit:CalendarExtender ID="tbSearchStartDate_CalendarExtender" runat="server" TargetControlID="tbSearchStartDate" /> 
    <br /> 
    <br /> 
    <asp:GridView ID="gvVALD" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDSSearchStartDate" > 
     <Columns> 
      <asp:BoundField DataField="StaffName" HeaderText="StaffName" SortExpression="StaffName" /> 
      <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" /> 
      <asp:BoundField DataField="StartDate" HeaderText="StartDate" SortExpression="StartDate" /> 
      <asp:BoundField DataField="Start Leave Period" HeaderText="Start Leave Period" SortExpression="Start Leave Period" /> 
      <asp:BoundField DataField="EndDate" HeaderText="EndDate" SortExpression="EndDate" /> 
      <asp:BoundField DataField="End Leave Period" HeaderText="End Leave Period" SortExpression="End Leave Period" /> 
      <asp:BoundField DataField="NumDays" HeaderText="NumDays" SortExpression="NumDays" /> 
     </Columns> 

    </asp:GridView> 
    <br /> 
    <asp:SqlDataSource ID="SqlDSSearchStartDate" runat="server" ConnectionString="<%$ ConnectionStrings:LeaveManagementCS %>" SelectCommand="SELECT Staff.StaffName, LeaveType.Type, LeaveApplications.StartDate, LeavePeriod.Description AS [Start Leave Period], LeaveApplications.EndDate, LeavePeriod.Description AS [End Leave Period], LeaveApplications.NumDays FROM LeaveApplications INNER JOIN LeavePeriod ON LeaveApplications.StartLeavePeriodId = LeavePeriod.LeavePeriodId AND LeaveApplications.EndLeavePeriodId = LeavePeriod.LeavePeriodId INNER JOIN LeaveType ON LeaveApplications.LeaveTypeId = LeaveType.Id INNER JOIN Staff ON LeaveApplications.StaffId = Staff.StaffId"></asp:SqlDataSource> 
</asp:Content> 

Asp.net.cs代码:

public partial class ViewAppliedLeaveByDate : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 

     } 
    } 
+0

您需要查询您的数据库,你在你的问题中提到的日期,你需要重新填充GridView控件在'tbSearchStartDate'文字上更改了事件 – Webruster

+0

,您希望在哪种情况下隐藏? –

回答

0

就文本框 “tbSearchStartDate” 一TextChanged事件将autopostback属性设置为true并通过提供您选择的内容再次绑定网格日期查询

0

只需设置GridView控件的Visible属性显示\隐藏:

gvVALD.Visible = false;