Setting the Default Sort for a DataGrid in SalesLogix Web REVISITED

A while back I wrote an article on setting the sort for a DataGrid in SalesLogix Web at runtime. That solution worked great in SalesLogix 7.2. However, things changed in SalesLogix 7.5 so I thought it was time for an update to that original post. Let’s see what changed and how to make it work again.

Take a look at the original article

In the original article, I mentioned that all this was possible because the SalesLogix DataGrid (Real class name SlxGridView) inherited from the ASP.NET GridView control. That hasn’t changed. However, here is what has changed:

Change #1: Where you LoadAction code is located

The original “C# Snippet Action Item” has been deprecated. This is what was used before. Now there is a “Code Snippet Action Item” is what is used for code in LoadActions. The reason why this is significant is that the deprecated “C# Snippet Action Item” was placed inline in the SmartPart/ASCX file. So, you could rely on the fact that you could easily just reference controls on the form since the code also existed on the form. Now, with the new “Code Snippet Action Item”, the code is compiled into a separate assembly, much like the code in business rules. You are passed a reference to the form – which is not really a reference to the SmartPart class itself, but instead via an object that implements IForm and IEntityForm.

Change #2: In LoadAction code, you no longer get a direct reference to the controls

This form object mentioned above exposes the controls on the form, however, not as the real control type, but as an adapter that wraps the control – only exposing certain things. For example, instead of exposing a reference to your SlxGridView (the datagrid), you get a reference to a faux-grid the implements IDataGridControl. This interface only provides access to a few handful of properties of the grid and the columns. The IDataGridControl implements IControl, which provides a few additional things, most notably, it provides a reference to the actual underlying control via an object property named NativeControl.

How do we make this work?

Using the IControl interface, you can take the control adapter you are passed in the LoadAction code and get to the native control. That is a simple task and then you’ll be able to do anything you need with the native control reference. Here’s some sample code that get’s a reference to the native control and then does the sorting, just like before:

public static partial class RelatedAccountsEventHandlers
public static void Step(IAccountTickets form, EventArgs args)
System.Web.UI.WebControls.GridView grid = (System.Web.UI.WebControls.GridView)form.grdAccountTickets.NativeControl;
grid.Sort("ReceivedDate", SortDirection.Descending);

Not so bad. The trick is knowing how to get to the underlying control from the adapter reference you are passed. One thing to note is that the code in the original article will still work in code in the now deprecated “C# Snippet Action Item”, so if you’ve used the code prior to 7.5, it will still work in the C# action. However, for new systems you need to use the new code above.


Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of He's been blogging regularly about SalesLogix since 2001 and believes in sharing with the community. He loves C#, Javascript, Python, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

1 Comment

  1. @RJ Samp

    Right! In SLX8 they did finally remove that (the “obsolete” wording) and has now actually become the preferred action once again. Using a C# Snippet Action is preferred in SLX8 over a Code Snippet Action (which can be C# or VB.NET) since a C# Snippet Action will work seamlessly with dynamic forms without a build/deploy.



Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) news and product updates!

You have Successfully Subscribed!