日历日渲染不在服务器端工作

时间:2012-04-25 09:18:38

标签: c# asp.net calendar

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

我的部分代码在这里:

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>

1 个答案:

答案 0 :(得分:0)

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

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

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