PDA

View Full Version : [CLOSED] How to bind EventStore to dataset in code behind.



GGage
Feb 05, 2013, 7:46 PM
Hello,

Where can I find an example of how to bind a CalendarPanel EventStore to a sql dataset in code behind?

Thanks
George

Baidaly
Feb 06, 2013, 12:45 AM
Hello!

Try the following code:



<%@ Page Language="C#" EnableViewState="true" %>

<%@ Import Namespace="System.Data" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
DataTable events = new DataTable();
events.Columns.Add(new DataColumn("EventId", typeof(int)));
events.Columns.Add(new DataColumn("Title", typeof(string)));
events.Columns.Add(new DataColumn("CalendarId", typeof(int)));
events.Columns.Add(new DataColumn("StartDate", typeof(DateTime)));
events.Columns.Add(new DataColumn("EndDate", typeof(DateTime)));
events.Columns.Add(new DataColumn("IsAllDay", typeof(bool)));

events.Rows.Add(1, "My Event", 1, DateTime.Now, DateTime.Now.AddHours(2), false);

this.CalendarPanel1.EventStore.DataSource = events;
this.CalendarPanel1.EventStore.DataBind();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Tree Reload test</title>
</head>
<body>
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<form id="Form1" runat="server">
<ext:Viewport runat="server" Layout="fit">
<Items>
<ext:CalendarPanel ID="CalendarPanel1" runat="server">
<EventStore runat="server" NoMappings="True" />
</ext:CalendarPanel>
</Items>
</ext:Viewport>
</form>
</body>
</html>

GGage
Feb 06, 2013, 2:37 PM
Thank you for the reply, but I was looking for something more like this:

CODE


protected void loadCalendarStore()
{

SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrin gs["dbString"].ConnectionString);

string strSQL = "select ";
strSQL += "rank() over (order by Requested_Dt) as CalendarId, ";
strSQL += "Pto.Sequence_Nbr as EventId, ";
strSQL += "Pto.Notes_Txt as Title, ";
strSQL += "convert( datetime, dateadd( hh, 12, Pto.Requested_Dt), 120 ) as StartDate, ";
strSQL += "convert( datetime, dateadd( hh, 15, Pto.Requested_Dt), 120 ) as EndDate, ";
strSQL += "Pto.Notes_Txt as Notes ";
strSQL += "from Person_TimeOffRequests Pto ";
strSQL += "where Pto.Employee_Cd = 'JDoe' ";

SqlCommand sqlCMD = new SqlCommand(strSQL, dbConn);
SqlDataAdapter sqlDA = new SqlDataAdapter();
sqlDA.SelectCommand = sqlCMD;

DataSet sqlDS = new DataSet();
sqlDA.Fill(sqlDS);

EventStore oEvtStore = new EventStore();
CalendarPanel1.EventStore = oEvtStore;

CalendarPanel1.EventStore.DataSource = sqlDS.Tables[0];
CalendarPanel1.EventStore.DataBind();

} // eof - loadCalendarStore()


MARKUP

<ext:CalendarPanel ID="CalendarPanel1" runat="server" >
<EventStore ID="EventStore1" runat="server" IgnoreExtraFields="false" />
</ext:CalendarPanel>



George






Hello!

Try the following code:



<%@ Page Language="C#" EnableViewState="true" %>

<%@ Import Namespace="System.Data" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
DataTable events = new DataTable();
events.Columns.Add(new DataColumn("EventId", typeof(int)));
events.Columns.Add(new DataColumn("Title", typeof(string)));
events.Columns.Add(new DataColumn("CalendarId", typeof(int)));
events.Columns.Add(new DataColumn("StartDate", typeof(DateTime)));
events.Columns.Add(new DataColumn("EndDate", typeof(DateTime)));
events.Columns.Add(new DataColumn("IsAllDay", typeof(bool)));

events.Rows.Add(1, "My Event", 1, DateTime.Now, DateTime.Now.AddHours(2), false);

this.CalendarPanel1.EventStore.DataSource = events;
this.CalendarPanel1.EventStore.DataBind();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Tree Reload test</title>
</head>
<body>
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<form id="Form1" runat="server">
<ext:Viewport runat="server" Layout="fit">
<Items>
<ext:CalendarPanel ID="CalendarPanel1" runat="server">
<EventStore runat="server" NoMappings="True" />
</ext:CalendarPanel>
</Items>
</ext:Viewport>
</form>
</body>
</html>

Daniil
Feb 06, 2013, 4:32 PM
Hi George,

@Baidaly just demonstrated what columns should have a DataTable to successfully bind it to an EventStore.

If needed I think you can set up a custom Model with required Fields for the EventStore.

Though, maybe, it is better to convert the DataTable (to meet the default Model Fields) on server side

GGage
Feb 06, 2013, 5:17 PM
Thank you Daniil,

This code now generates a JScript error as follows:

"Microsoft JScript error: Unable to get the value of the property 'getTime': object is null or undefined"

Thanks again
George



Hi George,

@Baidaly just demonstrated what columns should have a DataTable to successfully bind it to an EventStore.

If needed I think you can set up a custom Model with required Fields for the EventStore.

Though, maybe, it is better to convert the DataTable (to meet the default Model Fields) on server side

Baidaly
Feb 07, 2013, 2:10 AM
Thank you Daniil,

This code now generates a JScript error as follows:

"Microsoft JScript error: Unable to get the value of the property 'getTime': object is null or undefined"

Thanks again
George

Usually this error means wrong data on client side. Can you provide sample or response output?

GGage
Feb 10, 2013, 10:48 PM
Thank you,

I have some additional information on my problem. This error occurs when I nest the CalendarPanel in a PortalColumn.Portlet. as in the code below.


<ext:Viewport ID="Viewport1" runat="server" Layout="BorderLayout">
<Items>
<ext:Panel ID="pnlWest" runat="server" Region="West" Collapsible="true" Layout="AccordionLayout" Split="true" Width="200" >
<Items>
<ext:Panel ID="Panel1" runat="server" Border="true"
BodyPadding="6" Collapsible="true" Collapsed="false"
Icon="FolderWrench" Title="Menu" >
<Items>
<ext:Label ID="lblTest" runat="server" Text="Test" />
</Items>
</ext:Panel>

<ext:Panel ID="Panel2" runat="server" Border="false"
BodyPadding="6" Collapsible="true" Collapsed="true"
Icon="FolderWrench" Title="Your Options" >
<Items>

<ext:Button ID="Button3" runat="server" Text="Logout" Icon="Key">
</ext:Button>

</Items>
</ext:Panel>

</Items>
</ext:Panel>

<ext:Panel ID="pnlNorth" runat="server" Region="North" Header="true" Height="60" >
<Content>
<div id="titlebar">
<div id="left">
<div class="minor"></div>
<div class="title">
<span class="title-sub"></span>
</div>
</div>
<div id="right">
<ext:Label ID="lblMessage" runat="server" Text="Welcome : " />
</div>
</div>
</Content>
</ext:Panel>

<ext:TabPanel ID="tpnlCenter" runat="server" Region="Center" >
<Items>
<ext:Portal runat="server"
Border="false" BodyStyle="background-color: transparent;" MarginsSummary="5 5 5 0" Title="Desktop">
<Items>

<ext:PortalColumn ID="PortalColumn1" runat="server" ColumnWidth=".33" StyleSpec="padding:5px 0 5px 5px">
<Items>
<ext:Portlet ID="Portlet1" runat="server"
BodyPadding="0" MinHeight="150" Resizable="true"
Title="News / Events" >
</ext:Portlet>

<ext:Portlet ID="Portlet2" runat="server" Title="Panel 2" Resizable="true" />
</Items>
</ext:PortalColumn>

<ext:PortalColumn ID="PortalColumn2" runat="server" ColumnWidth=".33" StyleSpec="padding:5px 0 5px 5px">
<Items>
<ext:Portlet ID="Portlet3" runat="server" Title="Favorite Links" Resizable="true" />
<ext:Portlet ID="Portlet4" runat="server" Title="Accruals / PTO Requests" Resizable="true" >
<Items>

</Items>
</ext:Portlet>
</Items>
</ext:PortalColumn>

<ext:PortalColumn runat="server" ColumnWidth=".33" StyleSpec="padding:5px 0 5px 5px" >
<Items>
<ext:Portlet runat="server"
BodyPadding="0" MinHeight="350" Resizable="true"
Title="Calendar" >
<Items>

<ext:CalendarPanel ID="CalendarPanel1" runat="server" >
<EventStore ID="EventStore1" runat="server" IgnoreExtraFields="false" />
</ext:CalendarPanel>

</Items>
</ext:Portlet>
</Items>
</ext:PortalColumn>

</Items>
</ext:Portal>
</Items>
</ext:TabPanel>

</Items>
</ext:Viewport>

Thanks. Is there a way to do something like this?

Thanks George

Baidaly
Feb 11, 2013, 1:54 AM
I don't think that problem in the use of Portlets. Problem in data, please check all DateTime fields. I've tried the following example:



<%@ Page Language="C#" EnableViewState="true" %>

<%@ Import Namespace="System.Data" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
DataTable events = new DataTable();
events.Columns.Add(new DataColumn("EventId", typeof(int)));
events.Columns.Add(new DataColumn("Title", typeof(string)));
events.Columns.Add(new DataColumn("CalendarId", typeof(int)));
events.Columns.Add(new DataColumn("StartDate", typeof(DateTime)));
events.Columns.Add(new DataColumn("EndDate", typeof(DateTime)));
events.Columns.Add(new DataColumn("IsAllDay", typeof(bool)));

events.Rows.Add(1, "My Event", 1, DateTime.Now, DateTime.Now.AddHours(2), false);

this.CalendarPanel1.EventStore.DataSource = events;
this.CalendarPanel1.EventStore.DataBind();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Tree Reload test</title>
</head>
<body>
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<form id="Form1" runat="server">
<ext:Viewport ID="Viewport1" runat="server" Layout="BorderLayout">
<Items>
<ext:Panel ID="pnlWest" runat="server" Region="West" Collapsible="true" Layout="AccordionLayout" Split="true" Width="200" >
<Items>
<ext:Panel ID="Panel1" runat="server" Border="true"
BodyPadding="6" Collapsible="true" Collapsed="false"
Icon="FolderWrench" Title="Menu" >
<Items>
<ext:Label ID="lblTest" runat="server" Text="Test" />
</Items>
</ext:Panel>

<ext:Panel ID="Panel2" runat="server" Border="false"
BodyPadding="6" Collapsible="true" Collapsed="true"
Icon="FolderWrench" Title="Your Options" >
<Items>

<ext:Button ID="Button3" runat="server" Text="Logout" Icon="Key">
</ext:Button>

</Items>
</ext:Panel>

</Items>
</ext:Panel>

<ext:Panel ID="pnlNorth" runat="server" Region="North" Header="true" Height="60" >
<Content>
<div id="titlebar">
<div id="left">
<div class="minor"></div>
<div class="title">
<span class="title-sub"></span>
</div>
</div>
<div id="right">
<ext:Label ID="lblMessage" runat="server" Text="Welcome : " />
</div>
</div>
</Content>
</ext:Panel>

<ext:TabPanel ID="tpnlCenter" runat="server" Region="Center" >
<Items>
<ext:Portal runat="server"
Border="false" BodyStyle="background-color: transparent;" MarginsSummary="5 5 5 0" Title="Desktop">
<Items>

<ext:PortalColumn ID="PortalColumn1" runat="server" ColumnWidth=".33" StyleSpec="padding:5px 0 5px 5px">
<Items>
<ext:Portlet ID="Portlet1" runat="server"
BodyPadding="0" MinHeight="150" Resizable="true"
Title="News / Events" >
</ext:Portlet>

<ext:Portlet ID="Portlet2" runat="server" Title="Panel 2" Resizable="true" />
</Items>
</ext:PortalColumn>

<ext:PortalColumn ID="PortalColumn2" runat="server" ColumnWidth=".33" StyleSpec="padding:5px 0 5px 5px">
<Items>
<ext:Portlet ID="Portlet3" runat="server" Title="Favorite Links" Resizable="true" />
<ext:Portlet ID="Portlet4" runat="server" Title="Accruals / PTO Requests" Resizable="true" >
<Items>

</Items>
</ext:Portlet>
</Items>
</ext:PortalColumn>

<ext:PortalColumn runat="server" ColumnWidth=".33" StyleSpec="padding:5px 0 5px 5px" >
<Items>
<ext:Portlet runat="server"
BodyPadding="0" MinHeight="350" Resizable="true"
Title="Calendar" >
<Items>

<ext:CalendarPanel ID="CalendarPanel1" runat="server">
<EventStore runat="server" NoMappings="True" />
</ext:CalendarPanel>

</Items>
</ext:Portlet>
</Items>
</ext:PortalColumn>

</Items>
</ext:Portal>
</Items>
</ext:TabPanel>

</Items>
</ext:Viewport>
</form>
</body>
</html>

GGage
Feb 11, 2013, 4:13 PM
Thank you very much. One change solved it!

My problem was IgnoreExtraFields="false" instead of NoMappings="true" on the EventStore tag..

Thanks Again
George