Filtering a DataGrid in SalesLogix Web at Runtime

Binding a DataGrid at runtime is something that many SalesLogix developers are used to doing while working in the LAN client. This task is every bit as easy in the web platform as well. Let’s take a look at how to put this together.


For this example, we will put together a tab on the account page. We’ll call this tab “Related Accounts”. It will have a Picklist, showing the Account Types picklist, and a DataGrid. As the user selects an account type value in the picklist we will display all accounts with that account type. Not a really useful customization, but one that will allow us to see how to bind the grid up at runtime using a user selected value.

Building the Solution

To put this together, let’s start with building a busioness rule that we’ll use to return the data for the grid. You can read more about using GetByMethod to bind a grid to a rule in my previous articles: Creating a Business Rule to Return a List of Objects and Binding a Grid to a List Returning Rule using GetByMethod.

Our business rule will return a list of accounts and will take in one parameter, which will be the user selected account type value. The rule will look like this:

Name: GetRelatedAccounts
Return Type: System.Collections.Generic.IList<Sage.Entity.Interfaces.IAccount>

Add a parameter as follows (click on the Add link in the Parameters section):

Parameter Name: TypeValue
Type: String

Now for the code:

public static void GetRelatedAccountsStep(IAccount account, string TypeValue, out System.Collections.Generic.IList<Sage.Entity.Interfaces.IAccount> result)  
    IRepository<IAccount> repository = EntityFactory.GetRepository<IAccount>();
    IQueryable qry = (IQueryable)repository;
    IExpressionFactory ef = qry.GetExpressionFactory();

    ICriteria criteria = qry.CreateCriteria();
    criteria.Add(ef.Eq("Type", TypeValue));

    result = criteria.List<IAccount>();

Now, we’ll need one more business rule. The SalesLogix DataGrid control itself will throw an error if it does not have a DataSource set at build time. We’re not going to really use the SalesLogix DataSource component at all since we’ll be binding up the grid at runtime. However, it still requires this or it won’t build. To get around this we will have to add a DataSource component to the form as well. Now, we’ll also get errors if we have a DataSource component that is not set to return some data. We can’t use GetByMethod with our new rule we created since our rule takes a param and there is no way to set that for the DataSource. What we will do is create another business rule that returns a blank, empty list of accounts and we’ll use that for the DataSource, just so things compile.

This is what our empty rule will look like:

Name: GetEmptyAccountList
Return Type: System.Collections.Generic.IList<Sage.Entity.Interfaces.IAccount>

The code will be as follows:

public static void GetEmptyAccountListStep( IAccount account, out System.Collections.Generic.IList<Sage.Entity.Interfaces.IAccount> result)  
    result = new System.Collections.Generic.List<IAccount>();

Now you can use that rule that returns an empty list to set up as the GetByMethod for the DataSource component and then wire the DataSource to the grid. Also throw a Picklist onto the form using the Account Type picklist.

The picklist will have some code in the OnChange action. Add a “Code Snippet Action” to the OnChange of the Picklist control. The code for that will look as follows:

public static void picklistType_OnChangeStep(IRelatedAccounts form, EventArgs args)
    // Get a reference to the underlying ASP.NET GridView control
    System.Web.UI.WebControls.GridView grid = (System.Web.UI.WebControls.GridView)form.gridAccounts.NativeControl;
    // Make sure a value was selected in the Picklist
    if (form.picklistType.PickListValue != null && form.picklistType.PickListValue != string.Empty)
        // Get a reference to the account and call the rule, passing the picklist value
        IAccount account = form.CurrentEntity as IAccount;
        grid.DataSource = account.GetRelatedAccounts(form.picklistType.PickListValue);
        grid.DataSource = null;

     // Call the DataBind method of the GridView to set the binding

That is it. The key is to get a reference to the native underlying ASP.NET GridView control and then do the binding just as you would normally with that control. The end result will look like this:

I’ve also included a bundle of the code and form for this sample as an attachment to this article. Have fun.


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. Hi Tom,

    I would put that rule to return the empty list in the same entity as what you want to end up binding to the grid at runtime. For example, if you are going to be binding up a list of IAccount at runtime, put your rule, and the rule that returns the empty list of IAccount there (on the Account entity). This way it makes it possible to set up columns for the grid based on what the Account entity has.



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!