PDA

View Full Version : [CLOSED] How to populate a CalendarPanel from codebehind



jamesand
Jul 24, 2013, 11:40 AM
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(mobj ColEvtModel)
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.

Daniil
Jul 24, 2013, 2:26 PM
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(mobj ColEvtModel)
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.

Daniil
Jul 24, 2013, 2:45 PM
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.

jamesand
Jul 25, 2013, 12:14 PM
Ok perfect it works as expected. Thank you very much for your help.

jamesand
Jul 31, 2013, 8:45 AM
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(mobjC olEvtModel)

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.

Daniil
Jul 31, 2013, 12:55 PM
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();
}

jamesand
Aug 07, 2013, 3:30 PM
Hi Daniil, thank you it works.

Best regards.