【发布时间】:2016-08-06 04:48:33
【问题描述】:
我正在使用 asp.net gridview 和 ajax 日历扩展器。例如,用户选择像 19/8/16 这样的日期,那么它将仅在 gridview 表上显示 19/8/16 的日期。但问题是我不知道为 gridview 隐藏和显示什么代码。任何人都知道如何隐藏和显示gridview?
输出:
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)
{
}
}
【问题讨论】:
-
您需要在数据库中查询您在问题中提到的日期,并且您需要在
tbSearchStartDate文本更改事件上重新填充网格视图 -
您要根据哪个条件隐藏?
标签: c# asp.net gridview visual-studio-2015