Mar 28, 2014, 10:12 AM
[CLOSED] problem to render a grid to window from code behind
Hello I try to create a grid from code behind. I already do that, on other project, but here it is not working.
Here the code I use:
ASPX:
If found some topic in the forum, but I think it I can't apply in my code (something related to call can only be made from Ajax request and not on pae load, but I'm not on page load at that point of my code, the window is opened from a click on a menu item in my desktop
Here the code I use:
ASPX:
<Window>
<ext:Window
ID="wndCalendarTech"
runat="server"
Closable="true"
CloseAction="Destroy"
Minimizable="false"
Maximizable="false"
Resizable="true"
Height="800"
Icon="Wrench"
Title="Presence calendar"
Width="1200"
Modal="False"
Layout="FitLayout">
<Items>
<ext:Panel ID="panCalendarTech" runat="server" Border="false" >
<Loader runat="server" Url="LoadCalendarTech.ashx" Mode="Component">
<LoadMask ShowMask="true"></LoadMask>
</Loader>
<Listeners>
<Show Handler="#{panCalendarTech}.removeAll(); #{panCalendarTech}.reload();" />
</Listeners>
</ext:Panel>
</Items>
<Buttons>
<ext:Button runat="server" Text="Close">
<Listeners>
<Click Handler="#{wndCalendarTech}.close();"></Click>
</Listeners>
</ext:Button>
</Buttons>
</ext:Window>
</Window>
LoadCalendarTech.ashx:Imports System.Web
Imports System.Web.Services
Imports Ext.Net
Public Class LoadCalendarTech
Implements System.Web.IHttpHandler
Dim VMWebservice As fr2techsrv01.VisualManagementServices = New fr2techsrv01.VisualManagementServices
''' <summary>
''' This page will return presence calendar window for all technicians.
''' When a user load the window, this function is called. The return result is a JSON structure that conatains all control definition to fill tab
''' </summary>
''' <param name="context"></param>
''' <remarks>The controls are dynamically made as the number of days in a mont can vary
''' </remarks>
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "application/json" 'fix type of response object to return
Dim MyComponents As List(Of AbstractComponent) = New List(Of AbstractComponent) 'a list of all components that will be created
'geting data from database
Dim ds As DataSet = VMWebservice.getDatas("SELECT * FROM Technicians_T ORDER BY Name", "data", "AccessVM", ConfigurationManager.AppSettings("ENV"))
Dim myPanel As New TabPanel 'cretat the tabpanel that will receive all historic tabs
'as precedent panels contains grid, we have to create grid structure and store for each grid
'create elements needed by store
Dim ProxyCalendar As New AjaxProxy.Config 'store's proxy
Dim ReaderCalendar As New JsonReader 'store's reader
With ReaderCalendar
.Root = "data" 'define root property
End With
With ProxyCalendar 'set URL for store and different config parameters
.Url = "jsonDAL/returnJSONCalendarTech.aspx"
.Timeout = 300000000
.Reader.Add(ReaderCalendar)
End With
Dim StoreCalendar As New Store 'now create store
Dim ProxyCalendarTech As AjaxProxy = New AjaxProxy(ProxyCalendar)
Dim ModelFieldCalendar As New Model 'the store's model
'and create the model
ModelFieldCalendar.Name = "Model_Calendar"
ModelFieldCalendar.Fields.Add("id_tech") 'the fields that defines the store
ModelFieldCalendar.Fields.Add("Name")
'now we define field for next 30 days AM and PM
Dim StarDate As Date = Date.Now
Dim endDate = StarDate.AddDays(30)
Dim i As Integer = 0
Dim CurrenDate As Date = StarDate
While CurrenDate <= endDate
If CurrenDate.DayOfWeek <> DayOfWeek.Saturday And CurrenDate.DayOfWeek <> DayOfWeek.Sunday Then
ModelFieldCalendar.Fields.Add("DateAM" + i.ToString)
ModelFieldCalendar.Fields.Add("DatePM" + i.ToString)
CurrenDate = CurrenDate.AddDays(1)
i += 1
Else
CurrenDate = CurrenDate.AddDays(1)
End If
End While
With StoreCalendar 'fill store's parameter
.ID = "Store_CalendarTech"
.Model.Add(ModelFieldCalendar)
.Proxy.Add(ProxyCalendarTech)
End With 'all the store structure is created
'now deal with the grid
Dim grdCalendar As New GridPanel 'first the grid
Dim colidTech As New Column 'second, its column
Dim colName As New Column
Dim colDate As List(Of Column) = New List(Of Column)
With colidTech 'fill comumn structure with neede parameters
.ID = "id"
.DataIndex = "id_tech" 'from the store model structure
.Width = 80
.Hidden = True
End With
With colName
.ID = "TechName"
.DataIndex = "Name"
.Width = 150
.Text = "Technicians"
End With
CurrenDate = StarDate
i = 0
While CurrenDate <= endDate
If CurrenDate.DayOfWeek <> DayOfWeek.Saturday And CurrenDate.DayOfWeek <> DayOfWeek.Sunday Then
Dim colAM As New Column
Dim colPM As New Column
With colAM
.ID = "colAM" + i.ToString
.DataIndex = "DateAM" + i.ToString
.Width = 50
.Text = "AM"
End With
With colPM
.ID = "colPM" + i.ToString
.DataIndex = "DatePM" + i.ToString
.Width = 50
.Text = "PM"
End With
colDate.Add(colAM)
colDate.Add(colPM)
CurrenDate = CurrenDate.AddDays(1)
i += 1
Else
CurrenDate = CurrenDate.AddDays(1)
End If
End While
'now fill grid structure with needed parameters
With grdCalendar
.Cls = "x-grid-custom" 'class
.AutoScroll = True
.ColumnLines = True
.Height = 300
.SortableColumns = False
'the column model creates from previous columns created
.ColumnModel.Columns.Add(colidTech)
.ColumnModel.Columns.Add(colName)
For j As Integer = 0 To colDate.Count - 1
.ColumnModel.Columns.Add(colDate)
Next
.Store.Add(StoreCalendar) 'and finally grid store
End With
myPanel.Add(grdCalendar)
myPanel.Layout = "FitLayout"
ComponentLoader.Render(myPanel)
End Sub
''' <summary>
''' Added automaticaly at Handler page creation
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks>value set to false by defualt means current HTTP Handler will be release at end of request.
''' set value to true will keep the HTTP Handler in memory for next equest, but it must be created thread-safe to work.
''' Better way is to set value as default, impact is a lost on performance because garbage collector will have a litle more job to do to release unused
''' memory
''' </remarks>
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
and the error:
'Transformer.NET.TokenNotUniqueException'
Last edited by Daniil; Apr 04, 2014 at 4:42 PM.
Reason: [CLOSED]