0

我正在为一家中小型企业创建一个轮换系统,作为我在大学的最后一年项目。我正在尝试创建一个功能,用户可以在其中单击日历,系统将自动返回所选日期的班次。这是代码:

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Select date to show rota for selected date:
    </h2>
        <p>
            <asp:Calendar ID="Calendar" runat="server" nextprevformat="shortmonth" OnSelectionChanged="Calendar_SelectionChanged" />
            <br />
             Date Selected: <asp:TextBox id="textSelected" runat="server" Text="2013-02-21" AutoPostBack="true"></asp:TextBox>
        </p>
        <asp:Label id="lbl" runat="server"></asp:Label>
        <p>&nbsp;</p>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Shift_ID" DataSourceID="SqlDataSource1" onselectedindexchanged="GridView1_SelectedIndexChanged" AllowSorting="True">
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="Shift_ID" HeaderText="Shift_ID" ReadOnly="True" SortExpression="Shift_ID" />
            <asp:BoundField DataField="Shift_Date" HeaderText="Shift_Date" SortExpression="Shift_Date" />
            <asp:BoundField DataField="Start_Time" HeaderText="Start_Time" SortExpression="Start_Time" />
            <asp:BoundField DataField="End_Time" HeaderText="End_Time" SortExpression="End_Time" />
            <asp:BoundField DataField="Employee_ID" HeaderText="Employee_ID" SortExpression="Employee_ID" />
            <asp:BoundField DataField="Shift_Duration" HeaderText="Shift_Duration" SortExpression="Shift_Duration" />
        </Columns>
    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:rotasystemConnectionString %>" SelectCommand="SELECT [Shift_ID], [Shift_Date], [Start_Time], [End_Time], [Employee_ID], [Shift_Duration] FROM [Shift]">
    </asp:SqlDataSource>
    <p>&nbsp;</p>    
</asp:Content>

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class CalendarSelect : System.Web.UI.Page
{
    public string vconnstr;
    public string strsql;

    protected void Calendar_SelectionChanged(object o, EventArgs e)
    {
        textSelected.Text = Calendar.SelectedDate.ToString("yyyy-MM-dd");
        if (Page.IsPostBack == true)
        {
            lbl.Text = "This needs to return a gridview showing the shifts for the date of:";
            lbl.Text += "<br /> " + Calendar.SelectedDate.ToShortDateString();
        }
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { }
}
4

2 回答 2

1

检查这个http://msdn.microsoft.com/en-us/library/ms228044%28v=vs.100%29.aspx

我在我的项目中使用过它。

它肯定会帮助你。

于 2013-02-25T14:47:22.220 回答
0

即使我想这样做,我也是这样做的:
1- 拖放日历控件和网格视图
2- 将数据源添加到 gridview 并指定列,例如 select column1,2,3 from tablename where your_date_column = Control of the calendar . 配置数据源将为您提供选项选择控件
3- 并完成 :) 我的工作正常

于 2016-08-10T16:21:08.550 回答