SPCalendarView / sqlDataSource
-
Monday, October 13, 2008 2:38 AMHi,
I am trying to place an SPCalendarView in an aspx page and link it with a data source. I have configured the data source to return the data set that I need and upon placing it in the page with a data view I get to see all the information. However, I can't seem to figure out how to have the SPCalendarView control use the same data source and actually show the results. I am using the ID property of the sqlDataSource as the ID of the SPCalendarView control. The calendar shows up but does not contain the data. Here is how I am setting it up in the page.
Any help would be very much appreciated.
Thank you
<asp:SqlDataSource runat="server" ProviderName="System.Data.SqlClient" ID="SqlDataSource2" ConnectionString="Data Source=myserver;User ID=myUserID;Password=MyPassWord;Initial Catalog=WSS_Content;" SelectCommand="content of my select statement goes here" __designer:customcommand="true">
</asp:SqlDataSource><SharePoint:SPCalendarView runat="server" id="SPCalendarView1" DataSourceID="SqlDataSource2"></SharePoint:SPCalendarView>
All Replies
-
Tuesday, October 14, 2008 6:16 PMHi,
Your calendar view isn't working because of the following problem:
An SPCalendarView must be bind to DataSource of the type SPCalendarDataSource.
Well that looks easy, but now comes the difficult part. The SPCaledarDataSource object requires a list as datasource through the List property.
So to use the SPCalendarView you must use the SPCalendarDataSource and you must use a SharePoint list.
Maybe you can inherit from the SPCalendarView and modify the DataSource property, idea?
Hope this will help you a little bit more.
With kind regards,
Willem -
Monday, May 31, 2010 12:06 PM
Hi Willem,
do you know why this was changed totally? The class SPCalendarItemCollection is still be there.
-
Tuesday, July 20, 2010 5:08 PMSo basically if we used the SPCalendarView in SP2007 to manually create calendar items contained in SPCalendarItemCollection this control will not work for that in SP2010?
-
Tuesday, July 27, 2010 4:38 PMSet Enable V4 Rendering to false - the SPCalendarView will work. The rendering however will be of WSS 3.0 (non-ajax based).
- Proposed As Answer by ARoth09 Wednesday, August 18, 2010 8:43 PM
- Unproposed As Answer by Anjali Ch -MSFTMicrosoft Employee Friday, September 10, 2010 1:21 PM
-
Thursday, September 09, 2010 1:26 PM
Hi,
Are you able to reproduce issue in case the Webpart is inherited from Microsoft.SharePoint.WebPartPages.WebPart ? Use Microsoft namespace instead of System namespace for inheriting Webpart Class.
Share your test results.
AnjaliCH-MSFT -
Thursday, September 09, 2010 2:20 PMI was able to get this working. I've posted how I did it on my blog here: http://www.thelineberrys.com/default-category/spcalendarview-not-working-as-expected-in-sharepoint-foundation-2010-2.html
-
Thursday, September 09, 2010 7:19 PM
Hi ShockSLL,
You need NOT have to Set enable v4 rendering = false. You can achive the same thing as working in Sharepoint 2007 , in Sharepoint 2010, provided we inherit from Microsoft.SharePoint.WebPartPages.WebPart
The issue with System.Web.UI.WebControls.WebParts.WebPart class is related with javascript. Detailed post I will update soon.
AnjaliCH-MSFT -
Friday, September 24, 2010 3:57 PM
Hi
Sharing my detailed analysis:
Code tried with SPCalendar View
================================
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace SampleWebpart1
{
[Guid("cf5f3fd5-1776-4c47-9587-4f6fe4f3d645")]
public class SampleWebpart1 : Microsoft.SharePoint.WebPartPages.WebPart //System.Web.UI.WebControls.WebParts.WebPart
{
public SampleWebpart1() { }
protected override void CreateChildControls()
{
base.CreateChildControls();
SharePointCalendar calendar = new SharePointCalendar();
Controls.Add(calendar);
}
}
public class SharePointCalendar : Control
{
private SPCalendarView _view;
/// <summary>
/// Create the SharePoint calendar. Uses the SharePoint SPCalendarView object.
/// </summary>
protected override void CreateChildControls()
{
base.CreateChildControls();
_view = new SPCalendarView();
_view.EnableViewState = true;
_view.Width = Unit.Percentage(100);
_view.DataSource = GetCalendarItems();
DataBind();
Controls.Add(_view);
}
private SPCalendarItemCollection GetCalendarItems()
{
// Create a new collection for the calendar items
// This is an item with a start and end date.
SPCalendarItemCollection items = new SPCalendarItemCollection();
// Add the first dummy item
SPCalendarItem item = new SPCalendarItem();
item.StartDate = DateTime.Now;
item.EndDate = DateTime.Now.AddHours(1);
item.hasEndDate = true;
item.Title = "First calendar item";
item.DisplayFormUrl = "/News";
item.Location = "India";
item.Description = "This is the first test item in the calendar rollup";
item.IsAllDayEvent = false;
item.IsRecurrence = false;
item.CalendarType = Convert.ToInt32(SPCalendarType.Gregorian);
items.Add(item);
// Add the second item. This is an all day event.
SPCalendarItem item2 = new SPCalendarItem();
item2.StartDate = DateTime.Now.AddDays(-1);
item.hasEndDate = true;
item2.Title = "Second calendar item";
item2.DisplayFormUrl = "/News";
item2.Location = "India";
item2.Description = "This is the second test item in the calendar rollup";
item2.IsAllDayEvent = true;
item2.IsRecurrence = false;
item2.CalendarType = Convert.ToInt32(SPCalendarType.Gregorian);
items.Add(item2);
// return the collection
return items;
}
}
}
RESOLUTION/ WORKAROUND
========================
1. Webpart containing SPCalendarView ; inherting from System.Web.UI.WebControls.WebParts.WebPart has issues. The Day/ Month/Year & many more navigations & hyperlinks do not work.
2. SOLUTION: Webpart containing SPCalendarView ;inherting from Microsoft.SharePoint.WebPartPages.WebPart works with no issue.
NOTE: here we are not making any changes in rendering level. We still will get the v4 rendering looks.
ROOT CAUSE
==========
1. To find where the issue lies, let’s take the webpart inheriting from Microsoft.SharePoint.WebPartPages.WebPart
a. When the page where webpart is added, is rendered in the browser, (Check the View source) & try finding the below method.
NOTE: the method name is dynamic based on the webpart ID. The method name is built as : _spAjaxCalendarInit + WebpartId
function _spAjaxCalendarInitWPQ3(){
SP.UI.ApplicationPages.CalendarContainerFactory.create(document.getElementById('ctl00_m_g_c20623a8_a1f9_4b9a_a2f8_32fd4b34a10f_ctl01_ctl00_ctl01'),{ctxId:'WPQ3',dataSources:
[{id:'00000000-0000-0000-0000-000000000000',name:'',color:'',formUrl:'\u002f',primary:true, disableDrag:true}],userInfo:{current:{id:'1073741823',loginName:'SHAREPOINT\
\system',displayName:'System Account',email:''}},enablePeople:false,enableResource:false,usePostBack:true,canUserCreateItem:false,sharedPickerClientId:null,reservationContentTypeId:null,aM12String:'12:00
am',serviceUrl:null},'month','',[{"Options":41,"Table":null,"DatePicker":null,"Dates":
["8/29/2010","8/30/2010","8/31/2010","9/1/2010","9/2/2010","9/3/2010","9/4/2010","9/5/2010","9/6/2010","9/7/2010","9/8/2010","9/9/2010","9/10/2010","9/11/2010","9/12/2010","9/13
/2010","9/14/2010","9/15/2010","9/16/2010","9/17/2010","9/18/2010","9/19/2010","9/20/2010","9/21/2010","9/22/2010","9/23/2010","9/24/2010","9/25/2010","9/26/2010","9/27/2010","9
/28/2010","9/29/2010","9/30/2010","10/1/2010","10/2/2010","10/3/2010"],"RangeJDay":[149624,149658],"Navs":null,"Items":{"Data":[[0,1,2,149650,149650,3,3,4,5,8,1,60,0,0,0,6,0],
[0,7,2,149649,149650,8,3,4,9,8,1,1860,1,0,0,6,0]],"Strings":["","First calendar item","India","9/24/2010","8:01 am","9:01 am","/News","Second calendar item","9/23/2010","3:01
pm"]}}]);
}
b. Note the words which have been marked as bold in the above function.
c. Now, try finding the word: id="WebPartWPQ3"
d. We will find the <div> section which is actually the outer webpart rendering
e. Note one line below it (<div>) contains is: <span style="display:inline-block;width:100%;">
2. Now, let’s check the webpart inheriting from System.Web.UI.WebControls.WebParts.WebPart
a. When the page where webpart is added, is rendered in the browser, (Check the View source) & try finding the below method.
NOTE: the method name is dynamic based on the webpart ID. The method name is built as : _spAjaxCalendarInit + WebpartId
function _spAjaxCalendarInitctl00_m_g_c20623a8_a1f9_4b9a_a2f8_32fd4b34a10f_ctl01(){
SP.UI.ApplicationPages.CalendarContainerFactory.create(document.getElementById('ctl00_m_g_c20623a8_a1f9_4b9a_a2f8_32fd4b34a10f_ctl01_ctl00_ctl01'),
{ctxId:'ctl00_m_g_c20623a8_a1f9_4b9a_a2f8_32fd4b34a10f_ctl01',dataSources:[{id:'00000000-0000-0000-0000-000000000000',name:'',color:'',formUrl:'\u002f',primary:true,
disableDrag:true}],userInfo:{current:{id:'1073741823',loginName:'SHAREPOINT\\system',displayName:'System Account',email:''}},enablePeople:false,enableResource:false,usePostBack:true,canUserCreateItem:false,sharedPickerClientId:null,reservationContentTypeId:null,aM12String:'12:00
am',serviceUrl:null},'month','',[{"Options":41,"Table":null,"DatePicker":null,"Dates":
["8/29/2010","8/30/2010","8/31/2010","9/1/2010","9/2/2010","9/3/2010","9/4/2010","9/5/2010","9/6/2010","9/7/2010","9/8/2010","9/9/2010","9/10/2010","9/11/2010","9/12/2010","9/13
/2010","9/14/2010","9/15/2010","9/16/2010","9/17/2010","9/18/2010","9/19/2010","9/20/2010","9/21/2010","9/22/2010","9/23/2010","9/24/2010","9/25/2010","9/26/2010","9/27/2010","9
/28/2010","9/29/2010","9/30/2010","10/1/2010","10/2/2010","10/3/2010"],"RangeJDay":[149624,149658],"Navs":null,"Items":{"Data":[[0,1,2,149650,149650,3,3,4,5,8,14,60,0,0,0,6,0],
[0,7,2,149649,149650,8,3,4,9,8,14,1860,1,0,0,6,0]],"Strings":["","First calendar item","India","9/24/2010","8:14 am","9:14 am","/News","Second calendar item","9/23/2010","3:14
pm"]}}]);
}
b. Note the words which have been marked as bold in the above function.
c. Now, try finding the word: id="WebPartctl00_m_g_c20623a8_a1f9_4b9a_a2f8_32fd4b34a10f_ctl01". We won’t find
d. Now, try finding the word: id="WebPartctl00_m_g_c20623a8_a1f9_4b9a_a2f8_32fd4b34a10f". We will find the <div> section which is actually the outer webpart rendering
e. Note one line below it (<div>) contains is: <span id="ctl00_m_g_c20623a8_a1f9_4b9a_a2f8_32fd4b34a10f_ctl01" style="display:inline-block;width:100%;">
ISSUE
=====
>> Instead of passing the DIV id that is the webpart outer section id, we are passing the Span id, so when it internally tries finding for the webpart, it will never get. And, hence it cannot register the calendar view with the webpart.
>> This method contained in the file: SP.UI.ApplicationPages.Calendar.js (in the layouts folder) returns the webpart id by prefixing the webpart + the pass parameter value (what we have passed in the above method: highlighted id)
SP.UI.ApplicationPages.ElementUtility.$3f = function($p0) {
return $get('WebPart' + $p0);
}
>> JUST to test ONLY (NOTE: PLEASE DO NOT make any changes to OOB SharePoint files)
- ADD few lines of code to check if things work here with Webpart inheriting from System.Web.UI.WebControls.WebParts.WebPart
- In the file: SP.UI.ApplicationPages.Calendar.js (in the layouts folder)
SP.UI.ApplicationPages.ElementUtility.$3f = function($p0) {
/* ctl00_m_g_c20623a8_a1f9_4b9a_a2f8_32fd4b34a10f is the part of webpart id. Change as per your webpart id. */
if ($p0.toString().indexOf('ctl00_m_g_c20623a8_a1f9_4b9a_a2f8_32fd4b34a10f') > -1)
return $get('WebPart' + 'ctl00_m_g_c20623a8_a1f9_4b9a_a2f8_32fd4b34a10f');
return $get('WebPart' + $p0);
}
- Edited by Anjali Ch -MSFTMicrosoft Employee Friday, September 24, 2010 3:58 PM Formating
- Proposed As Answer by Anjali Ch -MSFTMicrosoft Employee Monday, September 27, 2010 1:34 PM
- Unproposed As Answer by Mike Walsh FIN Friday, December 03, 2010 7:22 PM
- Proposed As Answer by Anjali Ch -MSFTMicrosoft Employee Monday, December 20, 2010 2:40 PM
-
Thursday, October 28, 2010 4:34 AM
Anjali,
It seems the default behavior when I add SPCalendarItems manually in my custom webparts is they do not launch in the new SP2010 light box, like the out of the box calendar view does. And since I can only provide server relative URLs to the displayformurl property of both the SPCalendarview and the SPCalendarItems, I cannot inject javascript here. Do I need to override some function in SP.UI.ApplicationPages.Calendar.js, or am I missing some configuration somewhere?
--PB
-
Thursday, October 28, 2010 8:01 PM
I solved this for now by overriding a function that was rendered asynchrounously: EditLink2. Here is the standard function from Microsoft found in core.js in layouts:
function _EditLink2(elm, ctxNum)
{ULSsa6:;
var fn=function()
{ULSsa6:;
var url=GetGotoLinkUrl(elm);
if (url==null)
return;
var ctxT=window["ctx"+ctxNum];
if (ctxT !=null && ctxT.clvp !=null)
{
var clvp=ctxT.clvp;
if (FV4UI() && !ctxT.NavigateForFormsPages)
{
PreventDefaultNavigation();
clvp.ShowPopup(url);
return false;
}
}
GoToLink(elm);
}
EnsureScript("inplview", typeof(inplview), fn);
}My custom control always fails this test becasue ctxT.clvp is null for "some reason".
So I just overrode this function with:
function EditLink2(elm, ctxNum) {
var url = GetGotoLinkUrl(elm);
OpenPopUpPage(url, RefreshPage);
return false;}
- Marked As Answer by Mike Walsh FIN Friday, December 03, 2010 7:22 PM
-
Monday, December 20, 2010 2:42 PM
Hi Paul,
Hope you have not edited the OOB file. Its NOT SUPPORTED.
AnjaliCH-MSFT -
Monday, December 20, 2010 2:57 PM
No, I re-declared the EditLink2 function in my web part code, matching the Microsoft one exactly. So actually the function gets defined twice, once by Microsoft in core.js, and then again by me in my webpart. The more recent declaration of the java script function is the one that is utilized by the resulting page. I actually thought this would error, a function being defined twice, but thankfully for solving this problem, it did not.
It seems if there was some way to tell the SPCalendarView or the calendaritem itself that display url paramater should be treated as an absolute URL rather than relative, this could be avoided all together. But I'm sure there are lots of reasons it is implemetned the way it is.
Again, thankfully this worked, or I would have had to abandon SPCalendarView component all together.
-
Tuesday, July 24, 2012 12:54 PM
Hi Paul!
Could you please describe how you re-declared the EditLink2 function in your webpart? I think I'm facing a simliar problem when building a custom dropdownmenu for a webpart that lists documents from another documentlibrary.
I get and exception like "Unable to retrieve the value of the property clvp: object is null or undefined" in javascript function EditItem2 and perhaps your solution could work for me.
Regards!
//Johannes

