Through this blog, it is my effort to share experiences with the community and make the journey enjoyable.

Tuesday, September 30, 2008

Custom DataSheet View Using ListNet ActiveX Control

Introduction -

SharePoint DataSheet Page is used for editing lists in multiple record grid format. DataSheet view uses ListNet control, which is an ActiveX control. This control is also works in conjunction with the ListViewWebPart class to provide users with a dataview for editing lists in Microsoft Windows SharePoint Services.

ListNet control is defined in the STSLIST.DLL file, a dynamic-link library (DLL) that is installed on the client during 2007 Office system setup in the Local_Drive:\Program Files\Microsoft Office\OFFICE12 directory.

Analyzing out-of-box 'Edit in DataGrid' Page -

On clicking on 'Edit in DataGrid', redirection to 'AllItems.aspx' (~site/{DocLib}Forms/AllItems.aspx?ShowInGrid=True&View={ViewGuid}) happens.

In summary, looking at the source of the page, it contains Script tag, which calls Javascript function, RenderActiveX. RenderActiveX has the object tag with class id={65BCBEE4-7728-41a0-97BE-14E1CAE36AAE}.

Parameters which are set on the page, to render the ActiveX are - ListName, ViewGuid, ListWeb. ListData, ViewSchema, ListSchema.

In summary, below is the script tag -
<SCRIPT>RenderActiveX("<OBJECT id='STSListControlWPQ2' name='STSListControlWPQ2' classid=CLSID:65BCBEE4-7728-41a0-97BE-14E1CAE36AAE PARAM NAME='ListName' VALUE='{ListID} PARAM NAME=ViewGuid VALUE={ViewID} PARAM NAME=ListWeb VALUE={WebUrl} PARAM NAME='ListData' VALUE={ListData} PARAM NAME=ViewSchema VALUE={ViewSchema} PARAM NAME='ListSchema' VALUE={ListSchema} PARAM NAME='ControlName' VALUE='STSListControlWPQ2' > </OBJECT>");</SCRIPT>

Custom Application Page using ListNet ActiveX Page -
Below is some of the code snippet used in the application page. Application Page is passed two query parameters ListId and WebId, to create dynamic view for the list in the web.

<script runat="server">
SPWeb web;
SPList list;
string ListData, ViewSchema, ListSchema;

protected override void OnLoad(EventArgs e)
//Reading ListId querstring parameter
Guid listGuid = new Guid(Request.QueryString.Get("ListId"));

//Reading WebId querstring paramter
Guid webGuid = new Guid(Request.QueryString.Get("WebId"));

SPSite site = SPContext.Current.Site;
web = site.OpenWeb(webGuid);
list = web.Lists[listGuid];

//Custom string functions, STSHtmlEncode & STSScriptEncode to encode the string
ListData = STSScriptEncode(STSHtmlEncode(list.Items.Xml));
ViewSchema = STSScriptEncode(STSHtmlEncode(list.DefaultView.SchemaXml));
ListSchema = STSScriptEncode(STSHtmlEncode(list.SchemaXml));


<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<SCRIPT>RenderActiveX("\u003cOBJECT id=\u0022STSListControlWPQ2\u0022 name=\u0022STSListControlWPQ2\u0022 classid=CLSID:65BCBEE4-7728-41a0-97BE-14E1CAE36AAE width=\u002299\u0025\u0022 tabindex=\u00221\u0022\u003e\u003cPARAM NAME=\u0022ListName\u0022 VALUE=\u0022{<%=list.ID.ToString()%>}\u0022\u003e\u003cPARAM NAME=\u0022ViewGuid\u0022 VALUE=\u0022{<%=list.DefaultView.ID.ToString()%>}\u0022\u003e\u003cPARAM NAME=\u0022ListWeb\u0022 VALUE=\u0022<%=web.Url%>\u002f_vti_bin\u0022\u003e\u003cPARAM NAME=\u0022ListData\u0022 VALUE=\u0022<%=ListData%>\u0022\u003e\u003cPARAM NAME=\u0022ViewSchema\u0022 VALUE=\u0022<%=ViewSchema%>\u0022\u003e\u003cPARAM NAME=\u0022ListSchema\u0022 VALUE=\u0022<%=ListSchema%>\u0022\u003e\u003cPARAM NAME=\u0022ControlName\u0022 VALUE=\u0022STSListControlWPQ2\u0022\u003e\u003cp class=ms-descriptiontext\u003eThe Datasheet view of this list cannot be displayed. Please wait while the page is redirected to Standard view. If your list does not appear in a few moments, \u003cA onclick=\u0022javascript:GCNavigateToNonGridPage\u0028\u0029; javascript:return false;\u0022 href=\u0022?ShowInGrid=False\u0022 target=_self\u003eopen the list in Standard view\u003c\u002fA\u003e\u003c\u002fp\u003e\u003c\u002fOBJECT\u003e");



Monday, September 29, 2008

Switching between WebPart Pages Modes

Frequently, need for switching between different modes in WebPart page programmatically is felt. For this we have used using various SharePoint JavaScript functions like MSOTlPn_ShowToolPaneWrapper, MSOLayout_ToggleLayoutMode etc. have been used in the past.New approach for the switching between WebPart modes would be to use WebPartManager DisplayModes collection and setting DisplayMode.Below attached sample webpart code, achieves the same. When you load the page in a browser, Display Mode drop-down list control is populated with display modes and is used to switch to different display modes. To edit controls, select Edit in the drop-down list control. When you are finished, select Browse in the Display Mode drop-down list control to return the page to a normal view. To add controls to the page, switch to catalog mode.

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.HtmlControls;
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 SPUtil

public class EditModeSwitchWebPart : System.Web.UI.WebControls.WebParts.WebPart
DropDownList dropdownDisplayMode;
protected override void CreateChildControls()
dropdownDisplayMode = new DropDownList();
dropdownDisplayMode.AutoPostBack = true;
dropdownDisplayMode.SelectedIndexChanged += new EventHandler(dropdownDisplayMode_SelectedIndexChanged);

foreach (WebPartDisplayMode wpDisplayMode in WebPartManager.DisplayModes)
WebPartDisplayMode enabledWpDisplayMode = WebPartManager.SupportedDisplayModes[wpDisplayMode.Name];
if (enabledWpDisplayMode != null)

void dropdownDisplayMode_SelectedIndexChanged(object sender, EventArgs e)
if(this.dropdownDisplayMode.SelectedItem != null)
this.WebPartManager.DisplayMode = WebPartManager.DisplayModes[dropdownDisplayMode.SelectedValue];

Search This Blog


The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway. All posts are provided "AS IS" with no warranties, and confers no rights. In addition, my thoughts and opinions often change, and as a weblog is intended to provide a semi-permanent point in time snapshot you should not consider out of date posts to reflect my current thoughts and opinions.

Popular Posts

Total Pageviews