开发者

DayRender cell changes lost when a new date is selected

I am changing the background color for individual cells in the DayRender control, but when I select a different date the background color i chose for the cells are lost. I've looked around and can't really find what I am looking for. Hopefully the code will make it a bit more clear on what I want my code to do.

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{String sFullDate, sTradacomsDate;
    XmlNode node;

    sFullDate = e.Day.Date.Day.ToString("00") + "/" + e.Day.Date.Month.ToString("00") + "/" + e.Day.Date.Year.ToString();
    sTradacomsDate = e.Day.Date.Year.ToString().Substring(2,2) + e.Day.Date.Month.ToString("00") + e.Day.Date.Day.ToString("00");

    if (xmlDoc != null)
    {
        node = xmlDoc.SelectSingleNode("Dates/dbo.ASNs[FileDate = '" + sFullDate + "']");

        if (node != null)
        {
            e.Cell.BackColor = System.Drawing.Color.YellowGreen;
            e.Cell.ForeColor = System.Drawing.Color.White;
        }
    } 
    if (xmlDoc2 != null)
    {
        node = xmlDoc.SelectSingleNode("Dates/dbo.Orders[Da开发者_运维技巧teOrderPlaced = '" + sTradacomsDate + "']");

        if (node != null)
        {
            if (e.Cell.BackColor == System.Drawing.Color.Green)
            {
                e.Cell.BackColor = System.Drawing.Color.Orange;
                e.Cell.ForeColor = System.Drawing.Color.White;
            }
            else 
            {
                e.Cell.BackColor = System.Drawing.Color.Blue;
            }
        }
    }


My guess is that you don't have ViewState enabled for the control. When you select a date it performs a post back to handle the event; if ViewState is off and you don't reset the cell colors, they will revert to the default state. Make sure EnableViewState="true" is enabled at the page, user control, and Calendar control levels.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜