如何隐藏和显示Gridview表?

时间:2016-08-06 04:48:34

标签: c# asp.net gridview visual-studio-2015

我正在使用asp.net gridview和ajax日历扩展程序。例如,用户选择日期如19/8/16,那么它将仅在gridview表上显示19/8/16的日期。但问题是我不知道要为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)
        {

        }
    }

2 个答案:

答案 0 :(得分:0)

在文本框上创建一个textchanged事件&#34; tbSearchStartDate&#34;将autopostback属性设置为true,并通过将所选日期提供给查询来再次绑定网格

答案 1 :(得分:0)

只需设置GridView控件的Visible属性即可显示\ hide it:

gvVALD.Visible = false;