开发者

Generate dynamic calendar controls

How to generate dynamic controls based on selecton by user?

I had appeared for one practical test recently where they had the below mentioned requirements

  1. They had 2 calendars (asp.net default).

  2. They had two options (radio button list) : One was "Repeat On" and another "Repeated On"

The Repeat on had 2 drop down :

1) Day Dropdown: It values were: Every, Every Other Day, Every Third Day

2) Duration dropdown: It values were: Day, Month, Week, Year

The Repeated on had 2 drop down :

1) Week: the values were First Week, Second Week, Third Week

2) Day: Sunday, Monday .... Saturday

Now when i click the first calendar's date as say August 10 2010 and second one as January 26 2011,开发者_运维知识库 then i wanted that dynamic calendars should be generated that would show the Calendars from August to January (inclusive of both)

For Filter purpose, if i select First Sunday (From REPEATED ON Option) then first sunday of dynamic calendars should be selected. If i select every third day then every 3rd day should be selected (in dynamic generated calendars)

What i did was : Could generate dynamic calendars by creating object of calendar class.. is that right? Plus i searched on google and they show that DayRender Event could be a possible solution but that didn't help...

How to do that? How to generate dynamic calendar?

Please let me know if question is not being understood.

Pass me on code similar to that the least

thanks!


Sounds like what you want to do is set the properties Calendar.SelectedDate and Calendar.VisibleDate.

I'm not sure exactly what you're going for since I don't know what type of control the user will be selecting your Jan 1/Jun 1 dates from, or what the 3rd sunday has to do with that. Is there only one calendar? Please explain a little more if the info below doesn't help you.

I'll paste some VB code from one of my apps, hopefully it will help you out.

Protected Sub calArrival_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles calArrival.SelectionChanged
    SetFormDepartureEntry()

    lblArrivalDate.Text = calArrival.SelectedDate.ToLongDateString
    calDeparture.SelectedDate = calArrival.SelectedDate
    calDeparture.VisibleDate = calArrival.SelectedDate
    dtSelectedArrival = "1/1/2000"

    'Determine if we need to see 2 months to view all possible departure dates.
    If (DatePart(DateInterval.Month, calDeparture.SelectedDate) <> _
        DatePart(DateInterval.Month, DateAdd(DateInterval.Day, 14, calDeparture.SelectedDate))) Then
        calDeparture2.Visible = True
        calDeparture2.SelectedDate = Nothing
        calDeparture2.VisibleDate = DateAdd(DateInterval.Month, 1, calDeparture.SelectedDate)
    Else
        calDeparture2.Visible = False
    End If
    End Sub

OK now that you have posted the details this becomes a different question. You don't know how many calendars you need to so you will probably want to create them in code. I would suggest using a Panel control in your markup to contain all the possible result calendars. Then as you suggested earlier, create new Calendar objects as needed and add them to the "anchor" Panel's Controls collection.

Calendar objCal = new Calendar();
pnlResultsContainer.Controls.Add(objCal);

As far as setting selected days, you can only have one "selected" day per calendar I believe. However you can set the rendering styles, and whether the day is enabled, etc., by handling the Calendar.DayRender event. Maybe someone can help me out on setting up a handler for dynamically created controls in C#? I think it's something like:

objCal.DayRender += AddressOf(DynamicDayRenderHandler());

Please correct if this is not right.

Determining the correct day to set styles on in the handler will be a matter of coding against the DayRenderEventArgs.Day object which is a parameter of the event. I don't know offhand how to find the specific days/intervals you are looking for but it should be possible with a little research in the following articles:

How to: Customize Individual Days in a Calendar Web Server Control

DayRenderEventArgs.Day Property

Hope this helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜