简体   繁体   中英

Show dates in SQL in asp:Calendar

I am wondering if it's possible to have a set of dates in a SQL db and display in in a <asp:Calendar ID="Calendar1" runat="server"> for a user to select the dates available in a detailsview. Or if there's a better idea of displaying the dates?

Thanks.

To my knowledge, you cannot selectively remove dates from the ASP.NET Calendar control, but you can selectively disable dates by handling the DayRender event: just disable dates that are not in the set of dates returned from the database.

You might find a couple online examples helpful taking this approach - one in Bean Software's ASP.NET FAQ , another in DotNetSpider's forums .

Here is my stab at what you will need:

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
    // Disable the date being rendered if it is not in the DB-returned dates (as
    // List<DateTime> _databaseDates).
    if (!_databaseDates.Contains(e.Day.Date))
    {
        e.Day.IsSelectable = false;
        e.Cell.ForeColor = Color.Gray; // or e.Cell.Font.Strikeout = true;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM