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.

Scenario

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);
}
else
grid.DataSource = null;

// Call the DataBind method of the GridView to set the binding
grid.DataBind();
}

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
   Change the Appearance of a Saleslogix (Now Infor CRM) Read Only TextBox Web Control
In the Salelogix web client, a read only control has a css style applied to it to make the background app
Posted on Oct 24, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
   Saleslogix (now Infor CRM) Web Client- Changing Label Appearances on Quick Forms
 I wrote previously about setting a label's appearance on a quick form using server side code.&n
Posted on Oct 02, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
   Error Attempting to Save an Entity: "E_FAIL(0x80004005)" in the Infor CRM (Saleslogix) Web Client
We recently had a client that was running into an issue when attempting to create one particular entity i
Posted on Sep 30, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
   Video: Demystifying Infor CRM (Saleslogix) Updates
Watch it now! If you missed yesterdays demo, "Demystifying Infor CRM (Saleslogix) Updates" ,
Posted on Sep 26, 2014 by Brianna Ojard to The Inbox
 
   Official Infor CRM Acquisition FAQ
What to expect now that Saleslogix is Infor CRM. Like many of you, it will take some time (probably a
Posted on Sep 18, 2014 by Brianna Ojard to The Inbox
 
Comments

 

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

Thanks

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.

-Ryan

June 5, 2009 10:58 AM

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2014 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