Calendar .NET (v.2.2.0.0)  
Welcome to Calendar .NET Samples site!
Calendar Events
Getting Started
  Overview
  What`s new
Samples
  Getting Started!
  Data Binding
  Event Bar
  Handling Events
  Spanning Items
  Localization
  Other Samples
Contact us!
  Support Forum
  Email Us

Calendar Events

As in the DataGrid, you can fire a command from inside a Calendar template that is passed to an event handler wired to the Calendar itself. For example, a LinkButton inside the ItemTemplate might fire a Select command. By setting the OnItemCommand property of the Calendar, you can call an event handler in response to this command. The following example demonstrates this process.


[View C# Code]   [View VB.NET Code]

ASP.NET Form Code:


<ie:calendar OnItemCommand="Calendar_ItemCommand" id="CalendarCtrl" runat="server" 
     Width="100%" HighlightedDate="2003-08-19" SpanType="Overflowed" BorderStyle="Solid" 
     AbbriviatedDayNames="False" MaxDisplayedItems="6" ShowTime="false" 
     DataDescriptionField="Description" DataColorField="Color" DataTextField="Label" 
     DataLinkField="Link" ViewType="MonthView" DataStartDateField="Date" 
     DataEndDateField="EndDate" Palette="Windows" BorderWidth="1px" 
     ForeColor="#80FF80" Font-Names="Arial" CellSpacing="0" CellPadding="1" 
     TimescaleBottomLabelFormat="dd" TimescaleTopLabelFormat="dd, MMMM">
	<Items>
	    <ie:CalendarItem StartDate="2003-07-01" LabelColor="White" 
		    Label="Some label" EndDate="07/05/2003 23:59:00" >
	    </ie:CalendarItem>
	    <ie:CalendarItem StartDate="09/18/2003 13:29:00" LabelColor="White" 
		    Label="Some label" EndDate="09/23/2003 14:10:00">
	    </ie:CalendarItem>
	    <ie:CalendarItem StartDate="09/17/2003 13:29:00" LabelColor="White" 
		    Label="Some label" EndDate="09/21/2003 14:10:00">
	    </ie:CalendarItem>
	    <ie:CalendarItem StartDate="09/11/2003 13:29:00" LabelColor="White" 
		    Label="Some label" EndDate="09/16/2003 14:10:00">
	    </ie:CalendarItem>
	    <ie:CalendarItem StartDate="09/11/2003 13:29:00" LabelColor="White" 
		    Label="Some label" EndDate="09/30/2003 14:10:00">
	    </ie:CalendarItem>
	    <ie:CalendarItem StartDate="09/15/2003 13:29:00" LabelColor="White" 
		    Label="Some label" EndDate="09/16/2003 14:10:00">
	    </ie:CalendarItem>
	    <ie:CalendarItem StartDate="09/09/2003 22:14:00" LabelColor="White" 
		    Label="Some label" EndDate="09/16/2003 07:10:00">
	    </ie:CalendarItem>
	    <ie:CalendarItem StartDate="09/07/2003 22:25:00" LabelColor="White" 
		    Label="Some label" EndDate="09/16/2003 05:10:00">
	    </ie:CalendarItem>
	</Items>
	<TaskItemTemplate>
		<font color="black">
			<%#DataBinder.Eval(Container, "Label")%>
		</font>
	</TaskItemTemplate>
	<MonthItemTemplate>
	    <%#DataBinder.Eval(Container, "Label")%>
	    <asp:linkbutton CommandName="Command" runat="server" ID="Linkbutton1" 
	            NAME="Linkbutton1">
	        View Event
	    </asp:linkbutton>
	</MonthItemTemplate>
</ie:calendar>


C#, VB.NET Code:


  C#   VB  
 

<script runat="server">

    void Calendar_ItemCommand(Object sender, CalendarItemCommandEventArgs e) 
	{
        String command = e.CommandName;

        switch(command) {
          case "Command" :
            DisplayCommand(e.Item);
            break;
        }
    }

    void DisplayCommand(CalendarItem item) 
	{
        Message.InnerHtml = String.Format("Source Event: {0} - {1} {2}", 
        item.StartDate, item.EndDate, item.Label);
    }
    
</script>

<script runat="server">

    Protected Sub Calendar_ItemCommand(Sender As Object, E As CalendarItemCommandEventArgs)
        Dim Command As String = E.CommandName

        Select Case Command
            Case "Command"
                DisplayCommand(E.Item)
        End Select
    End Sub
    
    Protected Sub DisplayCommand(item as CalendarItem)
        Message.InnerHtml = String.Format("Source Event: {0} - {1} {2}", _
        item.StartDate, item.EndDate, item.Label)
    End Sub

</script>


Example source codes are included in Control Download.
 

Copyright 2005 Mediachase. All rights reserved.