Controlling List Size in ASP Pages

1 minute read time.

How can we override the User grid size preference for a custom list on ASP pages?

You may have seen that there is a List block property called RowsPerScreen

ListBlock.RowsPerScreen = 5;

On the face of it, this should allow us to change the list size to what ever we need. But according to Developers guide, "The user has a Grid Size set in their Preferences. This setting takes precedence over the RowsPerScreen setting"

In fact the RowsPerScreen as a property is only useful in the Self Service COM API

We need a way to manage the number of rows on a list in a custom ASP page to allow one screen to have List size of 15 and all others to default to whatever is set in the users preferences.

The technique we can use is to temporarily reset the users preferences so that we can control the list size.

See the code below

var intRecordId = CRM.GetContextInfo("company","comp_companyid");
var intOldGridSize = CRM.UserOption("NSet_GridSize");
CRM.UserOption("NSet_GridSize") = 10;
var myBlock = CRM.GetBlock("opportunitylist");
var Arg = "oppo_primarycompanyid="+intRecordId;
CRM.AddContent(myBlock.Execute(Arg));
Response.Write(CRM.GetPage());
CRM.UserOption("NSet_GridSize") = intOldGridSize;

I have used here the CRM.UserOption() to allow me to access the GridSize. The property is can be read and set.

Note: If you use this technique you will need to make sure that you reset the GridSize to the orginal value after the list has been created!