I am currently using Sharepoint 2013 foundation. I created a custom Web Part in Visual Studio to help filter a custom list on logged in users. Each logged in user will see a separate view. I then add the custom web part to a page, and it works great.
The only issue is it keeps the '+ new item' option and it adds a light gray border around the web part.
Would it be possible to add code to the custom web part to remove the '+ add new' and to remove the gray border.
Below is the c# for my custom web part:
using System;
using System.Data;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Collections.Generic;
using System.ComponentModel;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Administration;
using System.Collections;
namespace Custom_Webparts.Stab_List_Summary
{
[ToolboxItemAttribute(false)]
public partial class Stab_List_Summary : WebPart
{
// Uncomment the following SecurityPermission attribute only when doing Performance Profiling on a farm solution
// using the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
// for production. Because the SecurityPermission attribute bypasses the security check for callers of
// your constructor, it's not recommended for production purposes.
// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
public DCS_Stab_List_Summary()
{
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitializeControl();
}
protected void Page_Load(object sender, EventArgs e)
{
using (SPSite site = new SPSite("http://sitename")) // This URL needs to be changed to appropriate URL.
{
using (SPWeb web = site.OpenWeb())
{
// refer to the Stab List
SPList olist = web.Lists["Stab List"]; // "Stab List" needs to be changed to appropriate list name
//new XSLT webpart
XsltListViewWebPart webpart = new XsltListViewWebPart();
//custom XSLT Listview webpart properties
webpart.ListName = olist.ID.ToString("B").ToUpper();
webpart.AllowEdit = true;
webpart.AllowConnect = true;
webpart.AllowZoneChange = true;
//Refer views for different user
SPView oTView = olist.Views["Summary T"];
SPView oEView = olist.Views["Summary E"];
SPView oNormalView = olist.Views["Summary"];
//getthe logged in user name
SPUser oUser = SPContext.Current.Web.CurrentUser;
//If logged in user is T_sp, then apply appropriate view
if (oUser.Name.Contains("T_sp")) // t_sp
{
webpart.ViewGuid = oTView.ID.ToString("B");
}
else if (oUser.Name.Contains("E_sp")) // e_sp;
{
webpart.ViewGuid = oEView.ID.ToString("B");
}
// for other supply default view
else
{
webpart.ViewGuid = oNormalView.ID.ToString("B");
}
this.Controls.Add(webpart);
}
}
}
}
}
Here is a link to show an image of the gray border I am speaking about: