0

I'm creating the list view programmatically using the following code:

SPView myview = list.Views.Add(name, fields, query, 10, true, false);

how can I change the "There are no items to show in this view of the..." message using code?

1 Answer 1

1

Prior to SP 2013, common way of doing this was to use XSL template overrides. But in SP 2013, this can also be done using JSLink and CSR. Example:

(function () {
    var overrideCtx = {};
    overrideCtx.Templates = {};
    overrideCtx.Templates.OnPreRender = csrNoListItem;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
function csrNoListItem(ctx) {
    ctx.ListSchema.NoListItem = "Your own message";
}

Source: http://www.idubbs.com/blog/2015/jslink-csr-to-override-there-are-no-items-to-show-in-this-view/

UPDATE

SPView has ViewEmpty property. Try setting this property to your custom message.

4
  • Thank you @Nedeem, but I need to change it using code behind, because the users need to add it to different pages, and it will be difficult to them to add jslink every time they use this view, also why I need to bring the text form the server and change it on the client?
    – jobin
    Commented Feb 18, 2015 at 13:55
  • @jobin, see my updated answer. Commented Feb 18, 2015 at 15:36
  • I tried but it is not working, SPView view = list.Views.Add(name, fields, query, 10, true, false); view.ViewEmpty = "There are no items"; view.Update();
    – jobin
    Commented Feb 19, 2015 at 10:14
  • What would you change in order to get this to work for a document library? And for a bonus, how about highlighting this text?
    – Jordan
    Commented Mar 6, 2015 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.