-2

我创建了一个带有渲染选项的日历。它在我的本地机器上完美运行,但在服务器上不起作用。我在日历中展示了员工时间表,它在本地机器上工作正常。但现在我在服务器上发布它不在那里工作。

我的部分代码在这里:

if (e.Day.Date.Month == DateTime.Now.Month - 1)
{
    if ((lblfromdate.Text != "") && (lbltodate.Text != ""))
    {
        if (e.Day.Date < Convert.ToDateTime(lblfromdate.Text))
        {
            e.Cell.Text = string.Empty;
            e.Cell.BorderColor = System.Drawing.Color.White;
        }
        else
        {
            DataSet4TableAdapters.sp_getallholidayinfoTableAdapter TA = new DataSet4TableAdapters.sp_getallholidayinfoTableAdapter();
            DataSet4.sp_getallholidayinfoDataTable DS = TA.GetData();
            if (DS.Rows.Count > 0)
            {
                DataView DV = new DataView();
                DV = DS.DefaultView;
                string fromdate = Convert.ToString(lblfromdate.Text.Substring(5, 2) + "-" + lblfromdate.Text.Substring(8, 2) + "-" + lblfromdate.Text.Substring(0, 4));
                string todate = Convert.ToString(lbltodate.Text.Substring(5, 2) + "-" + lbltodate.Text.Substring(8, 2) + "-" + lbltodate.Text.Substring(0, 4));
                DV.RowFilter = "fldfromdate >=#" + fromdate + "# and fldfromdate <=#" + todate + "#";
                if (DV.Count > 0)
                {
                    string indate = Convert.ToString(DV[0]["fldfromdate"]);
                    string input = indate.Substring(6) + "-" + indate.Substring(0, 2) + "-" + indate.Substring(3, 2);
                    if (Convert.ToString(e.Day.Date.ToShortDateString()) == input)
                    {
                        e.Cell.Controls.Clear();
                        e.Cell.Text = "Holiday";
                        e.Cell.BackColor = System.Drawing.Color.BlueViolet;
                    }
                }
            }
        }
    }
}

我的设计代码:

<asp:Calendar ID="Calendar2" runat="server" BackColor="White"
    BorderColor="Black" BorderWidth="2px" Enabled="False"
    Font-Names="Verdana" Font-Size="9pt" ForeColor="Black"
    Height="183px" NextPrevFormat="FullMonth" ShowGridLines="True"
    Width="659px" OnDayRender="Calendar2_DayRender" ShowNextPrevMonth="False">

    <DayHeaderStyle BackColor="#6699FF" BorderStyle="Solid"
        Font-Bold="True" Font-Size="8pt" />

    <NextPrevStyle Font-Bold="True" Font-Size="8pt"
        ForeColor="#333333" VerticalAlign="Bottom" />

    <OtherMonthDayStyle ForeColor="#999999" />

    <SelectedDayStyle ForeColor="White" />

    <TitleStyle BackColor="White" BorderColor="Black" BorderStyle="None"
        Font-Bold="True" Font-Size="12pt" ForeColor="#333399" />

</asp:Calendar>
4

1 回答 1

0

与您的开发服务器相比,仔细检查服务器上的区域设置。

通常,当您将日期构建为字符串中的字符串,然后您的服务器从一个区域更改为另一个区域时,日期格式会出现问题

因此,如果您正在为“dd-MM-yyyy”构建一个字符串,那么服务器可能正在寻找“MM-dd-yyyy”

于 2012-04-25T09:53:57.720 回答