I really want to create some dependent datagrids using the SalesLogix Web client. Well it is not that I want to do so, but a Partner asked and I thought it was a neat customization. It turns out it has already been documented here, but that didn’t exactly work without modifications for me.
So I went a bit further. Rich provided some really good tips and some good code.
Things like:
- The second datagrid will get its datasource from a false getbymethod
- The code to dynamically load the second datagrid from the first will go in the OnRowSelected event
- Here is the iCriteria code you need
Which was all spot on and worked well for him. I took it a slightly different route which required some changes. Let’s see if I can explain.
The scenario
First, this is all documented in video format and the bundle is available via the developers subscription.
I wanted to use Projects as the basis for my customization. Really the partner wanted to use Project as the basis, so that is what I did. Remember that in the SalesLogix database there is already a table called “Projects.” In Application Architect I right clicked my Application Entities node and created an entity based on an existing table and left it at that. I then created my two new entities: projectstages and projecttasks. Projectstages is a child of projects and projecttasks is a child of stages. Joins were created as needed too.
Create the grids
The real trick is the Project entity is where the page will be created. It will have one datagrid for stages bound to a datasource based off of its projectstages property (the relationship). No big deal. Plenty of stuff in the videos for that.
The next datagrid was harder. It will be loaded on the selectedrowchange event of the other datagrid. So how can I get Application Architect to allow me to compile? That is where Rich’s other suggestion comes into play.
Create a business rule on the project entity that returns an empty iList of projecttasks:
Then you simply create a datasource based on that method (we do this a lot in classes and other examples, it is commonly called the getbymethod). You bind your datagrid to that datasource and now you can select the fields from the projecttask entity to display. This helps later when you really fill up the datagrid with some data — it will know which fields to show.
OnRowSelected
So now the code on the OnRowSelected Event:
System.Web.UI.WebControls.GridView myGrid =
(System.Web.UI.WebControls.GridView)form.grdPROJECTSTAGES.NativeControl;
int rowindex = myGrid.SelectedIndex;
foreach (System.Collections.DictionaryEntry val in myGrid.DataKeys[rowindex].Values)
{
if (val.Key.ToString() == "Id")
{
Sage.Platform.Repository.IRepository
Sage.Platform.EntityFactory.GetRepository
Sage.Platform.Repository.IQueryable qry = (Sage.Platform.Repository.IQueryable)pt;
Sage.Platform.Repository.IExpressionFactory ef = qry.GetExpressionFactory();
Sage.Platform.Repository.ICriteria criteria = qry.CreateCriteria();
criteria.Add(ef.Eq("PROJECTSTAGEId", val.Value.ToString() ));
System.Web.UI.WebControls.GridView myChildGrid =
(System.Web.UI.WebControls.GridView)form.dgTasks.NativeControl;
myChildGrid.DataSource = (criteria.List
myChildGrid.DataBind();
}
}
You can see it is pretty much the code we used for our iCriteria Examples here and here and here.
The code that may change when sp2 is released is here:
System.Web.UI.WebControls.GridView myGrid =
(System.Web.UI.WebControls.GridView)form.grdPROJECTSTAGES.NativeControl;
What I am doing here is taking the control from the form that is passed in and casting it into its asp.net equivalent. I do this because the SalesLogix Datgrid does not expose the .SelectedIndex property and later on I do it again for a another property and a method:
System.Web.UI.WebControls.GridView myChildGrid =
(System.Web.UI.WebControls.GridView)form.dgTasks.NativeControl;
myChildGrid.DataSource = (criteria.List
myChildGrid.DataBind();
The real key to the code is that the second datagrid expects a list of ProjectTasks. I provided that initially with my fake business rule and now I am doing it with:
myChildGrid.DataSource = (criteria.List
Cool? Comments? Suggestions? Can you do it?














