I have created a data view for for my custom list and is rendering in a sitepage. But, I'm missing the "New Item" link above the webpart now. This page contains multiple data filters too. This was previously there in the page when I previewed from the designer. But, after rendering from the Visual studio. It seems the New Item link is hidden some where in the page. Any idea to resolve this by getting that "New Item" link back ?
-
Do you have any CSS or javascript that may be hiding any elements or classes? I would say to edit the web part, and check that the Toolbar is not set to No Toolbar, but you say it shows when you preview it.wjervis– wjervis2014-01-16 18:58:57 +00:00Commented Jan 16, 2014 at 18:58
-
It shows in the preview for the first time when we creates the page in designer. I'm not able to get the webpart in the designer once deployed from visual studio!!Anish V– Anish V2014-01-17 03:24:31 +00:00Commented Jan 17, 2014 at 3:24
2 Answers
Anish,
This thread should help
using (SPLimitedWebPartManager mgrPageManager = pageOrganisation.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
SPList organisations = oHomeWeb.GetSafeListByName(SponsoringCommon.Constants.LISTNAMES_ORGANISATIONS2);
XsltListViewWebPart lvwpOrganisation = mgrPageManager.WebParts[idWebPartRootOrganisation] as XsltListViewWebPart;
Functions.SetToolbarType(lvwpOrganisation, "Freeform");
mgrPageManager.SaveChanges(lvwpOrganisation);
}
public static void SetToolbarType(XsltListViewWebPart lvwp, string viewType)
{
try
{
MethodInfo ensureViewMethod = lvwp.GetType().GetMethod("EnsureView", BindingFlags.Instance | BindingFlags.NonPublic);
object[] ensureViewParams = { };
ensureViewMethod.Invoke(lvwp, ensureViewParams);
FieldInfo viewFieldInfo = lvwp.GetType().GetField("view", BindingFlags.NonPublic | BindingFlags.Instance);
SPView view = viewFieldInfo.GetValue(lvwp) as SPView;
Type[] toolbarMethodParamTypes = { Type.GetType("System.String") };
MethodInfo setToolbarTypeMethod = view.GetType().GetMethod("SetToolbarType", BindingFlags.Instance | BindingFlags.NonPublic, null, toolbarMethodParamTypes, null);
object[] setToolbarParam = { viewType }; //set the type here
setToolbarTypeMethod.Invoke(view, setToolbarParam);
view.Update();
}
catch { }
}
UPDATE
A duplicate of:
Creating an XsltListViewWebPart programmatically: Columns & toolbar
-
I want it using jquery or javascript.Anish V– Anish V2014-01-17 03:25:01 +00:00Commented Jan 17, 2014 at 3:25
Did you select Insert Item link from InlineEditing option under option tab in data view webpart? As circled in below image.
Then it will generate one template inside dataview webpart which you can place above your table.
Template will be like:
<xsl:call-template name="dvt_1.rowinsert">
<xsl:with-param name="IsInsertMode">
<xsl:if test="$dvt_1_form_insertmode = '1'">1</xsl:if>
</xsl:with-param>
</xsl:call-template>

If you want to do it using Jquery simply add hyperlink which open new form for your customlist:
https://site url/Lists/ListName/newform.aspx
Hope this will help