protected virtual void CreateGridControls(IEnumerable<ProgramGrid> gridDefsData, 
            IEnumerable<ProgramGridDefinition> gridColDefsData, Control container)
        {
            foreach (var gridDef in gridDefsData.OrderBy(g => g.SequenceNumber))
            {
                var gridCtrl = new DataDefinedGridView();

                /// MUST set an ID, otherwise, ASP.NET will assign a tree-position-based one, which
                /// can make grids load the wrong viewstate after postbacks.
                gridCtrl.ID = gridDef.GridCode;

                gridCtrl.GridCode = gridDef.GridCode;
                gridCtrl.Caption = gridDef.Caption ?? gridDef.GridCode;
                gridCtrl.DataFetchCommand = gridDef.DataFetchCommand;
                gridCtrl.CommandInputParamNames = gridDef.InputParameters;
                gridCtrl.SkinID = "ddgrdView";

                /// Style as a regular row, instead of what is set in DataDefinedGridView's ctor.
                gridCtrl.SelectedRowStyle.CssClass = "selectableRow";

                gridCtrl.AddColumns(gridColDefsData, gridDef.GridCode);

                gridCtrl.TotalableDataFields = new string[] {
                    "SalesEligible", "SalesCumulativeCount", "SASEligible", "SASCumulativeCount",
                    "PotEarnings", "BonusEarnings", "TierEarnings", "TotalEarnings"
                };

                var dataKeys = Regex.Split(Regex.Replace(gridDef.DataKeyNames ?? blank, @"\s", blank), ",");
                if (dataKeys[0] != blank)
                    gridCtrl.DataKeyNames = dataKeys;
                else
                    gridCtrl.RowSelectionEnabled = false;

                var div = new HtmlGenericControl("div");
                div.Attributes.Add("class", "standingsReportTableWrapper");

                container.Controls.Add(div);
                div.Controls.Add(gridCtrl);

                GridList.Add(gridCtrl);
            }
        }
 private object[] GetParams(DataDefinedGridView grid)
 {
     return grid.InputParamValues.Select(p => p.Value).Cast<object>().ToArray();
 }
 private void SetInputAndDataBind(DataDefinedGridView grid, string paramName, object paramValue)
 {
     grid.InputParamValues[paramName.ToLower()] = paramValue;
     if (grid.Parent.Visible && grid.Visible)
         DataBindGrid(grid);
 }
 private void DataBindGrid(DataDefinedGridView grid)
 {
     var paramVals = GetParams(grid);
     var rows = DataFetcher.FetchData(grid.DataFetchCommand, paramVals).ToList();
     grid.DataBind(rows);
 }