开发者

how to display text in calender control from a database

开发者 https://www.devze.com 2023-03-18 03:04 出处:网络
i have a database with three rows id,des,date and i have a calender control but i would like to know how to display the text in the desc column into the cell that corresponds to the date in the date c

i have a database with three rows id,des,date and i have a calender control but i would like to know how to display the text in the desc column into the cell that corresponds to the date in the date column meaning :

id --- desc --- date
1  ||| test ||| 7/8/2011
2  ||| test2 ||| 8/8/2011
3  ||| test3 ||| 9/8/2011

so the cell that is the 7/8/开发者_StackOverflow社区2011 date in the calender should display test and 8/8/2011 should display test2 ... etc.

how can i achieve that , thanks


Use Calender.DayRender event to populate the calendar days from your data source.

One approach could be to get your data, make a property on your page that stores that data, then put your acquired data into the property.

Then, in the DayRender event, check the current date that is being processed, search your data source for data that correlates to that date, then display it. The link I provided shoes how to add HTML to a date.


Use the 'OnDayRender' event:

<asp:Calendar OnDayRender="DayRenderEventHandler" />

Code Behind:

function void DayRender(Object source, DayRenderEventArgs e) 
{
   // LINQtoSQL to get the desc
   string desc = (from d in db.CalendarTableName
                 where d.date == e.Day.Date
                 select d.desc).SingleOrDefault();
   // Add custom desc to cell in the Calendar control.
   e.Cell.Controls.Add(new LiteralControl("<br />" + desc));
}
0

精彩评论

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

关注公众号