2016-08-06 84 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;