[CLOSED] How to populate a CalendarPanel from codebehind

  1. #1

    [CLOSED] How to populate a CalendarPanel from codebehind

    Hi, I've been searching for a solution in the forums and I haven't been able to make it work properly.

    I just want to show some events in a CalendarPanel, populated in codebehind. Here it is the sample code I'm using:

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        
        Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
            Try
    
                Dim esC As New Ext.Net.EventStore.Config()
                esC.ItemID = "EventStore1"
                calEventosPedidos.EventStore = New Ext.Net.EventStore(esC)
    
                Dim mobjColEvtModel As New Ext.Net.EventModelCollection
                Dim objEvtModel As New Ext.Net.EventModel
    
                For i = 0 To 2
    
                    objEvtModel = New Ext.Net.EventModel
                    objEvtModel.CalendarId = 1
                    objEvtModel.EventId = i
                    objEvtModel.EndDate = Now
                    objEvtModel.IsAllDay = False
                    objEvtModel.Location = "My home"
                    objEvtModel.Notes = ""
                    objEvtModel.Reminder = ""
                    objEvtModel.StartDate = Now.AddHours(2)
                    objEvtModel.Title = "Family event"
                    objEvtModel.Url = ""
                    
                    mobjColEvtModel.Add(objEvtModel)
    
                Next
                'calEventosPedidos.EventStore.Events.AddRange(mobjColEvtModel)
                calEventosPedidos.EventStore.DataSource = mobjColEvtModel
                calEventosPedidos.EventStore.DataBind()
    
            Catch ex As Exception
    
                Exit Sub
            End Try
        End Sub
        
    </script>
       
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />        
       
            <ext:CalendarPanel
                ID="calEventosPedidos" 
                runat="server"
                Border="false">
                <CalendarStore ID="CalendarStoreEventosPedidos" runat="server">
                    <Calendars>
                        <ext:CalendarModel CalendarId="1" Title="Eventos" />
                    </Calendars>
                </CalendarStore>
                <MonthView ID="MonthView1" 
                    runat="server" 
                    ShowHeader="true" 
                    ShowWeekLinks="true" 
                    ShowWeekNumbers="true" 
                    />                
            </ext:CalendarPanel>
     
        </form>
    </body>
    </html>
    No events are shown and if I click the month view, no calendar is shown...

    I think it is a very basic question, but I need some help.

    Thank you in advance.
    Last edited by Daniil; Aug 06, 2013 at 8:28 AM. Reason: [CLOSED]
  2. #2
    Hi @jamesand,

    If you need to create an EventStore with an EventStore.Config, then please add:
    esC.LazyMode = LazyMode.Instance
    So:
    Dim esC As New Ext.Net.EventStore.Config()
    esC.LazyMode = LazyMode.Instance
    esC.ItemID = "EventStore1"
    calEventosPedidos.EventStore = New Ext.Net.EventStore(esC)
    Or do not use an EventStore.Config.
    Dim es As New Ext.Net.EventStore()
    es.ItemID = "EventStore1"
    calEventosPedidos.EventStore = es
    Also please uncomment
    'calEventosPedidos.EventStore.Events.AddRange(mobjColEvtModel)
    and remove
    calEventosPedidos.EventStore.DataSource = mobjColEvtModel
    calEventosPedidos.EventStore.DataBind()
    Also you might need to set up some Height for the CalendarPanel, it doesn't stretch automatically.
  3. #3
    Quote Originally Posted by Daniil View Post
    If you need to create an EventStore with an EventStore.Config, then please add:
    esC.LazyMode = LazyMode.Instance
    It has been fixed in SVN. After updating from SVN there will be no need to set up it manually.
  4. #4
    Ok perfect it works as expected. Thank you very much for your help.
  5. #5
    Hi Daniil again, what if I want to filter the events in server side by using a DirectEvent?

    I added a ToolBar with one textbox and one button. When you press the button it calls a DirectEvent where the events are filtered by reading a database.
    But even no founding events, the calendarpanel remains showing the same events are before.
    How do I clear the previous events in order to show the filtered ones??

    <ext:Toolbar ID="Toolbar1" runat="server" Height="27">
                                    <Items>
                                        <ext:TextField ID="txtCiudadBusqueda" runat="server" FieldLabel="Ciudad" />
                                        <ext:Button ID="FiltrarButton" runat="server" Text="Filtrar" Icon="Zoom">
                                            <DirectEvents>
                                                <Click OnEvent="Filtrar_Click">
                                                </Click>
                                            </DirectEvents>
                                        </ext:Button>
                                    </Items>
                                </ext:Toolbar>
    Public Sub Filtrar_Click(ByVal sender As Object, ByVal e As Ext.Net.DirectEventArgs)
    
            Dim interfaceDB As New EventsInterface()
    
            Try
                Dim events As Object
    
                events = interfaceDB.GetEvents(txtCiudadBusqueda.Text)
    
                Dim es As New Ext.Net.EventStore()
                es.ItemID = "EventStore1"
                calEventosPedidos.EventStore = es
    
                Dim mobjColEvtModel As New Ext.Net.EventModelCollection
                Dim objEvtModel As New Ext.Net.EventModel
    
                For i = 0 To events.Count - 1
    
                    objEvtModel = New Ext.Net.EventModel
                    objEvtModel.CalendarId = 1
                    objEvtModel.EventId = events(i).ID_EVENT
                    objEvtModel.EndDate = events(i).DATE.AddHours(1).AddMinutes(45)
                    objEvtModel.IsAllDay = False
                    objEvtModel.Location = events(i).LOCATION
                    objEvtModel.Notes = ""
                    objEvtModel.Reminder = ""
                    objEvtModel.StartDate = events(i).DATE
                    objEvtModel.Title = events(i).EVENT_NAME
                    objEvtModel.Url = ""
                    mobjColEvtModel.Add(objEvtModel)
    
                Next
    
                calEventosPedidos.EventStore.Events.AddRange(mobjColEvtModel)
    
            Catch ex As Exception
                MostrarPanelMensaje("alert alert-error", "No se han podido recuperar los eventos. Error: " & ex.Message)
                Exit Sub
            End Try
    
        End Sub
    Even if "events" has no values, the same events are shown in the CalendarPanel.

    I also tried by adding: calEventosPedidos.EventStore.Events.Clear(), but no luck.

    Thank you in advance.
  6. #6
    It is how it should be done.

    Example (C#)
    protected void Filter(object sender, DirectEventArgs e)
    {
        this.CalendarPanel1.EventStore.RemoveAll();
        this.CalendarPanel1.EventStore.Events.Clear();
        this.CalendarPanel1.EventStore.Events.Add(new EventModel() 
        { 
            EventId = 5,
            Title = "New",
            StartDate = DateTime.Now,
            EndDate = DateTime.Now.AddDays(5),
            CalendarId = 1
        });
    
        this.CalendarPanel1.EventStore.DataBind();
    }
  7. #7
    Hi Daniil, thank you it works.

    Best regards.

Similar Threads

  1. Replies: 5
    Last Post: Mar 19, 2013, 3:27 AM
  2. Replies: 9
    Last Post: Nov 21, 2012, 8:08 PM
  3. Populate Multiselect
    By ddolan in forum 1.x Help
    Replies: 1
    Last Post: Apr 13, 2011, 1:09 PM
  4. Replies: 0
    Last Post: Jan 04, 2011, 8:25 PM
  5. [CLOSED] Populate a MultiSelect in codebehind
    By SFritsche in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Jun 15, 2009, 7:32 PM

Tags for this Thread

Posting Permissions