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;
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.