Login / Register  search  syndication  about

          Ryan Farley's Blog

Ryan Farley on .NET Development with a focus on CRM Development for SalesLogix

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.

What's This?
Bookmark and Share

About Ryan Farley

   Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. 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.

View the SalesLogix Mobile Seveloper Series
View the SalesLogix SData Developer Series
View the Git for the SalesLogix Developer series

Related Content
   Can I Bind an Attachment to a Specific Activity in Infor CRM version 7.54?
Recently I had a user ask if they could bind an attachment to a specific Activity within Infor CRM??
Posted on Jul 07, 2015 by Dale Richter to Infor CRM Questions & Answers
   Infor CRM (Formerly Saleslogix) Iterating through all tabs on a Page
 Using the TabWorskpace you can iterate through all the tabs on a page and do something with them, l
Posted on Jun 19, 2015 by Kris Halsrud to Kris Halsrud's Blog
   Infor CRM (Formerly Saleslogix) Hiding Tabs at Runtime Without Using Modules
 As Ryan wrote a long time ago, you can create a module and add it to a page in the Infor CRM web cl
Posted on Jun 10, 2015 by Kris Halsrud to Kris Halsrud's Blog
   How I assign ownership to a group of Leads in Infor CRM?
There is a tool within Infor CRM to align Accounts to different Account Owners. It is called Territory Re
Posted on Jun 05, 2015 by Dale Richter to Infor CRM Questions & Answers
   Infor CRM (Formerly Saleslogix) Adding a Client Side Confirmation on a Dependency Lookup in the Web Client
 We recently had a client who wanted to have a user confirmation prompt before a user was allowed to
Posted on May 28, 2015 by Kris Halsrud to Kris Halsrud's Blog


Mark Dykun said:

Excellent article Ryan. Very simple to follow.

April 2, 2009 2:13 PM

Ryan Farley said:

Thanks Mark.

April 2, 2009 2:57 PM

RIch Eaton said:

As Always Ryan, getting done the things we need most often in easy to follow steps..


April 2, 2009 5:56 PM

Tom said:

How would I accomplish this on an entity-less form? Where would I create the business rule that returns blank data?

June 2, 2009 10:21 AM

Ryan Farley said:

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.


June 5, 2009 10:58 AM

Leave a Comment

All contents Copyright © 2015 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783

  Follow @CustomerFX on twitter
Follow the best news, tips, and articles
  Subscribe to Customer FX on youtube
Watch SalesLogix tutorial videos from Customer FX
Login / Register