I have a web user control that allows the user to run one of several available canned reports from a rad combo box. I'm able to specify which report to run and specify a few basic criteria when producing the first report. Afterwards, however, if I select a different report (which programmatically generates the columns in a rad grid and selects the appropriate data source) after returning to the criteria screen I receive this error:
Error: Sys.WebForms.PageRequestManagerServerErrorException: There was a problem extracting DataKeyValues from the DataSource. Please ensure that DataKeyNames are specified correctly and all fields specified exist in the DataSource.
After further investigation, it seems as if the DataKeyValues the grid is expecting "lags" behind because I can keep running the same report with different criteria so long as the report type remains the same. As soon as I change report types (which use differnet DataKeyValues), the grid does not appear to update with those values (still uses the DataKeyValues from the previous report) and fails. I'm hoping someone else can shed some light on the situation. I've provided my interface and server-side code below.
User Control Interface:
Page Interface:
User Control Code-Behind
Page Code-Behind
Thanks in advance.
Error: Sys.WebForms.PageRequestManagerServerErrorException: There was a problem extracting DataKeyValues from the DataSource. Please ensure that DataKeyNames are specified correctly and all fields specified exist in the DataSource.
After further investigation, it seems as if the DataKeyValues the grid is expecting "lags" behind because I can keep running the same report with different criteria so long as the report type remains the same. As soon as I change report types (which use differnet DataKeyValues), the grid does not appear to update with those values (still uses the DataKeyValues from the previous report) and fails. I'm hoping someone else can shed some light on the situation. I've provided my interface and server-side code below.
User Control Interface:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ReportManager.ascx.cs" Inherits="AZ.SA.RL.App.ProgramManagement.Controls.ReportManager" %>
<
telerik:RadCodeBlock
ID
=
"ControlScripts"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function onRequestStart(sender, args) {
if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
args.get_eventTarget().indexOf("ExportToWordButton") >= 0 ||
args.get_eventTarget().indexOf("ExportToCsvButton") >= 0) {
args.set_enableAjax(false);
}
}
</
script
>
</
telerik:RadCodeBlock
>
<
telerik:RadAjaxManager
ID
=
"Report_ScriptManager"
runat
=
"server"
>
<
ClientEvents
OnRequestStart
=
"onRequestStart"
/>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"Result_Grid"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"Result_Grid"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxPanel
ID
=
"ControlContainer_AjaxPanel"
runat
=
"server"
CssClass
=
"ContentBlock"
Style
=
"width:auto"
>
<
h3
><
asp:Label
ID
=
"ControlHeader_Label"
runat
=
"server"
Text
=
"Quick Report"
/></
h3
>
<
asp:ValidationSummary
ID
=
"QuickReport_ValidationSummary"
runat
=
"server"
ShowMessageBox
=
"false"
ShowSummary
=
"true"
ValidationGroup
=
"QuickReportValidation"
/>
<
asp:Panel
ID
=
"QuickReport_Panel"
runat
=
"server"
Visible
=
"true"
>
<
ul
>
<
li
>
<
asp:Label
ID
=
"QuickReportType_Label"
runat
=
"server"
AssociatedControlID
=
"QuickReportType_Combobox"
Text
=
"Quick Report"
/>
<
telerik:RadComboBox
ID
=
"QuickReportType_Combobox"
runat
=
"server"
/>
</
li
>
</
ul
>
<
ul
>
<
li
>
<
asp:Label
ID
=
"StartDate_Label"
runat
=
"server"
AssociatedControlID
=
"QuickReportStartDate_DatePicker"
Text
=
"Start Date"
/>
<
telerik:RadDatePicker
ID
=
"QuickReportStartDate_DatePicker"
runat
=
"server"
>
<
ShowAnimation
Type
=
"Fade"
Duration
=
"500"
/>
<
HideAnimation
Type
=
"Fade"
Duration
=
"500"
/>
</
telerik:RadDatePicker
>
<
asp:RequiredFieldValidator
ID
=
"QuickReportStartDate_RequiredField"
runat
=
"server"
ControlToValidate
=
"QuickReportStartDate_DatePicker"
CssClass
=
"Validator"
Display
=
"Dynamic"
ErrorMessage
=
"Please specify a start date in the Start Date field."
SetFocusOnError
=
"true"
Text
=
"*"
ValidationGroup
=
"QuickReportValidation"
/>
<
asp:CompareValidator
ID
=
"QuickReportStartDate_StartDateBeforeEndDate"
runat
=
"server"
ControlToValidate
=
"QuickReportStartDate_DatePicker"
ControlToCompare
=
"QuickReportEndDate_DatePicker"
CssClass
=
"Validator"
Display
=
"Dynamic"
ErrorMessage
=
"The start date of a report must come before its end date."
Operator
=
"LessThanEqual"
SetFocusOnError
=
"true"
Text
=
"*"
Type
=
"Date"
ValidationGroup
=
"QuickReportValidation"
/>
</
li
>
</
ul
>
<
ul
>
<
li
>
<
asp:Label
ID
=
"EndDate_Label"
runat
=
"server"
AssociatedControlID
=
"QuickReportEndDate_DatePicker"
Text
=
"End Date"
/>
<
telerik:RadDatePicker
ID
=
"QuickReportEndDate_DatePicker"
runat
=
"server"
>
<
ShowAnimation
Type
=
"Fade"
Duration
=
"500"
/>
<
HideAnimation
Type
=
"Fade"
Duration
=
"500"
/>
</
telerik:RadDatePicker
>
<
asp:RequiredFieldValidator
ID
=
"QuickReportEndDate_RequiredField"
runat
=
"server"
ControlToValidate
=
"QuickReportEndDate_DatePicker"
CssClass
=
"Validator"
Display
=
"Dynamic"
ErrorMessage
=
"Please specify an end date in the Start Date field."
SetFocusOnError
=
"true"
Text
=
"*"
ValidationGroup
=
"QuickReportValidation"
/>
</
li
>
</
ul
>
<
ul
>
<
li
>
<
asp:Label
ID
=
"Options_Label"
runat
=
"server"
AssociatedControlID
=
"QuickReportIncludeQuickReport_CheckBoxList"
Text
=
"Options"
/>
<
div
class
=
"CheckBoxList"
>
<
asp:CheckBoxList
ID
=
"QuickReportIncludeQuickReport_CheckBoxList"
runat
=
"server"
RepeatLayout
=
"UnorderedList"
>
<
asp:ListItem
Text
=
"Include Quick Plans"
Value
=
"0"
/>
</
asp:CheckBoxList
>
</
div
>
</
li
>
</
ul
>
<
asp:Button
ID
=
"RunReport_Button"
runat
=
"server"
CausesValidation
=
"true"
OnClick
=
"RunReport_Button_Click"
Text
=
"Run Report"
ValidationGroup
=
"QuickReportValidation"
/>
</
asp:Panel
>
<
asp:Panel
ID
=
"CustomReport_Panel"
runat
=
"server"
>
</
asp:Panel
>
<
asp:Panel
ID
=
"Result_Panel"
runat
=
"server"
Visible
=
"false"
>
<
telerik:RadGrid
ID
=
"Result_Grid"
runat
=
"server"
ExportSettings-ExportOnlyData
=
"true"
ExportSettings-OpenInNewWindow
=
"true"
ExportSettings-IgnorePaging
=
"true"
ExportSettings-HideStructureColumns
=
"true"
OnNeedDataSource
=
"Result_Grid_NeedDataSource"
OnDetailTableDataBind
=
"Result_Grid_DetailTableDataBind"
OnGridExporting
=
"Result_Grid_GridExporting"
OnItemDataBound
=
"Result_Grid_ItemDataBound"
Skin
=
"Black"
>
<
MasterTableView
AllowPaging
=
"true"
AutoGenerateColumns
=
"false"
CommandItemDisplay
=
"Top"
CommandItemSettings-ShowExportToCsvButton
=
"false"
CommandItemSettings-ShowExportToExcelButton
=
"true"
CommandItemSettings-ShowExportToPdfButton
=
"false"
CommandItemSettings-ShowExportToWordButton
=
"true"
CommandItemSettings-ShowAddNewRecordButton
=
"false"
GroupLoadMode
=
"Server"
Name
=
"ReportResults"
HierarchyDefaultExpanded
=
"true"
HierarchyLoadMode
=
"ServerBind"
PagerStyle-AlwaysVisible
=
"true"
PagerStyle-Mode
=
"NextPrevNumericAndAdvanced"
PagerStyle-Position
=
"Top"
PageSize
=
"30"
TableLayout
=
"Fixed"
>
<
DetailTables
>
<
telerik:GridTableView
AutoGenerateColumns
=
"true"
Name
=
"DetailResults"
OnDataBound
=
"Result_DetailGrid_OnDataBound"
OnPreRender
=
"Result_DetailGrid_PreRender"
BorderStyle
=
"None"
ShowHeader
=
"false"
TableLayout
=
"Fixed"
>
</
telerik:GridTableView
>
</
DetailTables
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
asp:Panel
>
</
telerik:RadAjaxPanel
>
Page Interface:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ReportView.ascx.cs" Inherits="AZ.SA.RL.App.ProgramManagement.ReportView" %>
<%@ Register Src="~/Controls/ReportManager.ascx" TagName="ReportManager" TagPrefix="pm" %>
<
telerik:RadAjaxManagerProxy
ID
=
"Program_AjaxManager"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"Report_Toolbar_ButtonClick"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"Report_ReportManager"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManagerProxy
>
<
asp:UpdatePanel
ID
=
"Toolbar_AjaxPanel"
runat
=
"server"
UpdateMode
=
"Conditional"
>
<
ContentTemplate
>
<
telerik:RadToolBar
ID
=
"Report_Toolbar"
runat
=
"server"
Skin
=
"Black"
BorderStyle
=
"None"
BorderWidth
=
"0"
OnButtonClick
=
"Report_Toolbar_ButtonClick"
Width
=
"100%"
>
<
Items
>
<
telerik:RadToolBarDropDown
Text
=
"New Report"
DropDownWidth
=
"150px"
>
<
Buttons
>
<
telerik:RadToolBarButton
Text
=
"Quick Report"
CommandName
=
"NEW"
Value
=
"Quick"
/>
<
telerik:RadToolBarButton
Text
=
"Custom Report"
CommandName
=
"NEW"
Value
=
"Custom"
Enabled
=
"false"
Visible
=
"false"
/>
</
Buttons
>
</
telerik:RadToolBarDropDown
>
<
telerik:RadToolBarButton
IsSeparator
=
"true"
Value
=
"Sep1"
/>
<
telerik:RadToolBarButton
Text
=
"Criteria"
CommandName
=
"CRITERIA"
Checked
=
"true"
CheckOnClick
=
"true"
Group
=
"PlanType"
/>
<
telerik:RadToolBarButton
Text
=
"Results"
CommandName
=
"RESULTS"
Checked
=
"false"
CheckOnClick
=
"true"
Group
=
"PlanType"
/>
</
Items
>
</
telerik:RadToolBar
>
</
ContentTemplate
>
</
asp:UpdatePanel
>
<
asp:UpdatePanel
ID
=
"Content_AjaxPanel"
runat
=
"server"
UpdateMode
=
"Conditional"
>
<
ContentTemplate
>
<
div
class
=
"ContentContainer"
>
<
pm:ReportManager
ID
=
"Report_ReportManager"
runat
=
"server"
/>
</
div
>
</
ContentTemplate
>
</
asp:UpdatePanel
>
User Control Code-Behind
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
using
AZ.SA.RL.App.ProgramManagement.Objects;
using
System.ComponentModel;
namespace
AZ.SA.RL.App.ProgramManagement.Controls
{
public
partial
class
ReportManager : System.Web.UI.UserControl
{
//Enumerators
#region Enumerators
public
enum
QuickReportType
{
ByProgrammingCenter = 0,
ByPrimaryOrganizer = 1,
ByOutcomes = 2
}
public
enum
OpMode
{
Quick = 0,
Custom = 1
}
public
enum
DispMode
{
Criteria = 0,
Results = 1
}
#endregion
//Properties
#region Properties
/// <summary>
/// Gets or sets the current quick report being run by the manager.
/// </summary>
[Browsable(
true
),
Category(
"Function"
),
DefaultValue(QuickReportType.ByProgrammingCenter)]
public
QuickReportType QuickReport
{
get
{
QuickReportType result = QuickReportType.ByProgrammingCenter;
if
(ViewState[
"__QUICKREPORT"
] !=
null
)
{
result = (QuickReportType)ViewState[
"__QUICKREPORT"
];
}
return
result;
}
set
{
ViewState[
"__QUICKREPORT"
] = value;
}
}
/// <summary>
/// Gets or sets the current operation mode of the manager.
/// </summary>
[Browsable(
true
),
Category(
"Function"
),
DefaultValue(OpMode.Quick)]
public
OpMode OperationMode
{
get
{
OpMode result = OpMode.Quick;
if
(ViewState[
"__OPERATIONMODE"
] !=
null
)
{
result = (OpMode)ViewState[
"__OPERATIONMODE"
];
}
return
result;
}
set
{
ViewState[
"__OPERATIONMODE"
] = value;
}
}
/// <summary>
/// Gets or sets the current display mode of the manager.
/// </summary>
[Browsable(
true
),
Category(
"Function"
),
DefaultValue(DispMode.Criteria)]
public
DispMode DisplayMode
{
get
{
DispMode result = DispMode.Criteria;
if
(ViewState[
"__DISPLAYMODE"
] !=
null
)
{
result = (DispMode)ViewState[
"__DISPLAYMODE"
];
}
return
result;
}
set
{
ViewState[
"__DISPLAYMODE"
] = value;
//ControlContainer_AjaxPanel.RaisePostBackEvent("__DISPLAYMODECHANGED");
}
}
/// <summary>
/// Sets the title for the manager
/// </summary>
[Browsable(
true
),
Category(
"Data"
),
DefaultValue(
"No Title"
)]
public
string
Title
{
private
get
{
string
result =
"No Title"
;
if
(ViewState[
"__TITLE"
] !=
null
)
{
result = (
string
)ViewState[
"__TITLE"
];
}
return
result;
}
set
{
ViewState[
"__TITLE"
] = value;
}
}
/// <summary>
/// Stores the start datetime for quick report filter
/// </summary>
[Browsable(
false
),
Category(
"Data"
),
DefaultValue(
null
)]
private
DateTime ReportStartDate
{
get
{
DateTime result =
default
(DateTime);
if
(ViewState[
"__STARTDATE"
] !=
null
)
{
result = (DateTime)ViewState[
"__STARTDATE"
];
}
return
result;
}
set
{
ViewState[
"__STARTDATE"
] = value;
}
}
/// <summary>
/// Stores the end datetime for quick report filter
/// </summary>
[Browsable(
false
),
Category(
"Data"
),
DefaultValue(
null
)]
private
DateTime ReportEndDate
{
get
{
DateTime result =
default
(DateTime);
if
(ViewState[
"__ENDDATE"
] !=
null
)
{
result = (DateTime)ViewState[
"__ENDDATE"
];
}
return
result;
}
set
{
ViewState[
"__ENDDATE"
] = value;
}
}
#endregion
//Methods - Custom
#region Methods - Custom
protected
void
RenderView()
{
Label controlHeader = ControlHeader_Label;
Panel quickReportPanel = QuickReport_Panel;
Panel customReportPanel = CustomReport_Panel;
Panel resultPanel = Result_Panel;
switch
(DisplayMode)
{
case
DispMode.Criteria:
resultPanel.Visible =
false
;
if
(OperationMode == OpMode.Quick)
{
quickReportPanel.Visible =
true
;
customReportPanel.Visible =
false
;
}
else
if
(OperationMode == OpMode.Custom)
{
quickReportPanel.Visible =
false
;
customReportPanel.Visible =
true
;
}
break
;
case
DispMode.Results:
if
(OperationMode == OpMode.Quick)
{
resultPanel.Visible =
true
;
quickReportPanel.Visible =
false
;
customReportPanel.Visible =
false
;
}
else
if
(OperationMode == OpMode.Custom)
{
}
break
;
}
if
(DisplayMode == DispMode.Criteria)
{
if
(OperationMode == OpMode.Custom)
{
Title =
"Custom Report Criteria"
;
}
else
{
Title =
"Quick Report Criteria"
;
}
}
//Modify the header to show the current report
controlHeader.Text = Title;
}
protected
void
PopulateQuickReports(
object
sender)
{
RadComboBox quickReportList = (RadComboBox)sender;
foreach
(QuickReportType quickReportEnum
in
Enum.GetValues(
typeof
(QuickReportType)))
{
int
value = (
int
)Enum.Parse(
typeof
(QuickReportType), quickReportEnum.ToString());
RadComboBoxItem reportItem =
new
RadComboBoxItem(quickReportEnum.ToString(), value.ToString());
quickReportList.Items.Add(reportItem);
QuickReportType itemValue = (QuickReportType)value;
switch
(itemValue)
{
case
QuickReportType.ByProgrammingCenter:
reportItem.Text =
"By Programming Center"
;
break
;
case
QuickReportType.ByPrimaryOrganizer:
reportItem.Text =
"By Primary Organizer"
;
break
;
case
QuickReportType.ByOutcomes:
reportItem.Text =
"By Primary Goal"
;
break
;
}
}
}
protected
void
RenderReportGrid(
object
sender, QuickReportType reportType)
{
RadGrid reportGrid = (RadGrid)sender;
GridBoundColumn boundColumn =
null
;
reportGrid.MasterTableView.AutoGenerateColumns =
false
;
reportGrid.MasterTableView.TableLayout = GridTableLayout.Fixed;
reportGrid.Columns.Clear();
switch
(reportType)
{
case
QuickReportType.ByProgrammingCenter:
Title =
"Quick Report - Programs by Programming Center ("
+ ReportStartDate.ToShortDateString() +
" - "
+ ReportEndDate.ToShortDateString() +
")"
;
reportGrid.MasterTableView.ClientDataKeyNames =
new
string
[] {
"DepartmentUnitId"
};
if
(reportGrid.Columns.Count <= 0)
{
//Add the Program Name column
boundColumn =
new
GridBoundColumn();
reportGrid.Columns.Add(boundColumn);
boundColumn.DataField =
"UnitName"
;
boundColumn.HeaderText =
"Programming Center"
;
boundColumn.UniqueName =
"UnitName"
;
//Add the Program Name column
boundColumn =
new
GridBoundColumn();
reportGrid.Columns.Add(boundColumn);
boundColumn.DataField =
"UnitShortName"
;
boundColumn.HeaderText =
"Unit Short NAme"
;
boundColumn.UniqueName =
"UnitShortName"
;
boundColumn.Visible =
false
;
//Add the Program Name column
boundColumn =
new
GridBoundColumn();
reportGrid.Columns.Add(boundColumn);
boundColumn.DataField =
"DepartmentUnitId"
;
boundColumn.HeaderText =
"DepartmentUnitId"
;
boundColumn.UniqueName =
"DepartmentUnitId"
;
boundColumn.Visible =
false
;
//Add the Program Count column
boundColumn =
new
GridBoundColumn();
reportGrid.Columns.Add(boundColumn);
boundColumn.DataField =
"ProgramCount"
;
boundColumn.HeaderText =
"ProgramCount"
;
boundColumn.UniqueName =
"ProgramCount"
;
boundColumn.Visible =
false
;
}
break
;
case
QuickReportType.ByPrimaryOrganizer:
Title =
"Quick Report - Programs by Primary Organizer ("
+ ReportStartDate.ToShortDateString() +
" - "
+ ReportEndDate.ToShortDateString() +
")"
;
reportGrid.MasterTableView.DataKeyNames =
new
string
[] {
"PrimaryOrganizerName"
,
"GroupId"
};
if
(reportGrid.Columns.Count <= 0)
{
//Add the Program Name column
boundColumn =
new
GridBoundColumn();
reportGrid.Columns.Add(boundColumn);
boundColumn.DataField =
"PrimaryOrganizerName"
;
boundColumn.HeaderText =
"Primary Organizer"
;
boundColumn.UniqueName =
"PrimaryOrganizerName"
;
//Add the Program Name column
boundColumn =
new
GridBoundColumn();
reportGrid.Columns.Add(boundColumn);
boundColumn.DataField =
"GroupName"
;
boundColumn.HeaderText =
"Group Name"
;
boundColumn.UniqueName =
"GroupName"
;
boundColumn.Visible =
false
;
//Add the Program Name column
boundColumn =
new
GridBoundColumn();
reportGrid.Columns.Add(boundColumn);
boundColumn.DataField =
"GroupId"
;
boundColumn.HeaderText =
"GroupId"
;
boundColumn.UniqueName =
"GroupId"
;
boundColumn.Visible =
false
;
//Add the Program Count column
boundColumn =
new
GridBoundColumn();
reportGrid.Columns.Add(boundColumn);
boundColumn.DataField =
"ProgramCount"
;
boundColumn.HeaderText =
"ProgramCount"
;
boundColumn.UniqueName =
"ProgramCount"
;
boundColumn.Visible =
false
;
}
break
;
case
QuickReportType.ByOutcomes:
Title =
"Quick Report - Programs by Primary Goal ("
+ ReportStartDate.ToShortDateString() +
" - "
+ ReportEndDate.ToShortDateString() +
")"
;
reportGrid.MasterTableView.DataKeyNames =
new
string
[] {
"BaseOutcomeId"
};
if
(reportGrid.Columns.Count <= 0)
{
//Add the Program Name column
boundColumn =
new
GridBoundColumn();
reportGrid.Columns.Add(boundColumn);
boundColumn.DataField =
"PrimaryGoalName"
;
boundColumn.HeaderText =
"Primary Goal"
;
boundColumn.UniqueName =
"PrimaryGoalName"
;
//Add the Base Outcome Id column
boundColumn =
new
GridBoundColumn();
reportGrid.Columns.Add(boundColumn);
boundColumn.DataField =
"BaseOutcomeId"
;
boundColumn.HeaderText =
"BaseOutcomeId"
;
boundColumn.UniqueName =
"BaseOutcomeId"
;
boundColumn.Visible =
false
;
//Add the Program Count column
boundColumn =
new
GridBoundColumn();
reportGrid.Columns.Add(boundColumn);
boundColumn.DataField =
"ProgramCount"
;
boundColumn.HeaderText =
"ProgramCount"
;
boundColumn.UniqueName =
"ProgramCount"
;
boundColumn.Visible =
false
;
}
break
;
}
//Set the export file name to the title
reportGrid.ExportSettings.FileName = Title;
}
protected
void
RenderDetailGrid(
object
sender, QuickReportType reportType)
{
//RadGrid reportGrid = (RadGrid)sender;
//GridTableView detailGrid = reportGrid.MasterTableView.DetailTables[0];
GridTableView detailGrid = (GridTableView)sender;
GridBoundColumn boundColumn =
null
;
GridDateTimeColumn dateColumn =
null
;
detailGrid.AutoGenerateColumns =
false
;
detailGrid.TableLayout = GridTableLayout.Fixed;
switch
(reportType)
{
case
QuickReportType.ByProgrammingCenter:
break
;
case
QuickReportType.ByPrimaryOrganizer:
if
(detailGrid.Columns.Count <= 0)
{
//Add the Program Name column
boundColumn =
new
GridBoundColumn();
detailGrid.Columns.Add(boundColumn);
boundColumn.DataField =
"ProgramName"
;
boundColumn.HeaderText =
"Program Name"
;
boundColumn.UniqueName =
"ProgramName"
;
//boundColumn.HeaderStyle.Width = Unit.Percentage(30);
//boundColumn.ItemStyle.Width = Unit.Percentage(30);
//Add the Primary Goal column
boundColumn =
new
GridBoundColumn();
detailGrid.Columns.Add(boundColumn);
boundColumn.DataField =
"PrimaryGoalName"
;
boundColumn.HeaderText =
"Primary Goal"
;
boundColumn.UniqueName =
"PrimaryGoalName"
;
//boundColumn.HeaderStyle.Width = Unit.Percentage(30);
//boundColumn.ItemStyle.Width = Unit.Percentage(30);
//Add the Start Date column
dateColumn =
new
GridDateTimeColumn();
detailGrid.Columns.Add(dateColumn);
dateColumn.DataField =
"StartDate"
;
dateColumn.HeaderText =
"Start Date"
;
dateColumn.UniqueName =
"StartDate"
;
//dateColumn.HeaderStyle.Width = Unit.Percentage(20);
//dateColumn.ItemStyle.Width = Unit.Percentage(20);
//Add the End Date column
dateColumn =
new
GridDateTimeColumn();
detailGrid.Columns.Add(dateColumn);
dateColumn.DataField =
"EndDate"
;
dateColumn.HeaderText =
"End Date"
;
dateColumn.UniqueName =
"EndDate"
;
//dateColumn.HeaderStyle.Width = Unit.Percentage(20);
//dateColumn.ItemStyle.Width = Unit.Percentage(20);
}
break
;
case
QuickReportType.ByOutcomes:
break
;
}
}
#endregion
//Methods - Event Handling
#region Methods - Event Handling
protected
void
Page_PreRender(
object
sender, EventArgs e)
{
RadComboBox quickReportList = QuickReportType_Combobox;
if
(quickReportList.Items.Count <= 0)
{
PopulateQuickReports(quickReportList);
}
RenderView();
}
protected
void
RunReport_Button_Click(
object
sender, EventArgs e)
{
Page.Validate(
"QuickReportValidation"
);
if
(Page.IsValid)
{
RadComboBox quickReportTypeList = QuickReportType_Combobox;
RadDatePicker startDatePicker = QuickReportStartDate_DatePicker;
RadDatePicker endDatePicker = QuickReportEndDate_DatePicker;
DateTime startDate =
default
(DateTime);
DateTime endDate =
default
(DateTime);
QuickReportType quickReportType = (QuickReportType)
int
.Parse(quickReportTypeList.SelectedValue);
if
(startDatePicker.SelectedDate.HasValue)
startDate = startDatePicker.SelectedDate.Value;
if
(endDatePicker.SelectedDate.HasValue)
endDate = endDatePicker.SelectedDate.Value;
//Set the quick report type
QuickReport = quickReportType;
OperationMode = OpMode.Quick;
DisplayMode = DispMode.Results;
ReportStartDate = startDate;
ReportEndDate = endDate;
Result_Grid.Rebind();
}
}
protected
void
Result_Grid_GridExporting(
object
sender, GridExportingArgs e)
{
RadGrid reportGrid = (RadGrid)sender;
switch
(e.ExportType)
{
case
ExportType.Excel:
reportGrid.MasterTableView.ExpandCollapseColumn.Visible =
false
;
//reportGrid.MasterTableView.Columns.RemoveAt(0);
//reportGrid.MasterTableView.Columns.RemoveAt(0);
//reportGrid.MasterTableView.Visible = false;
break
;
}
}
protected
void
Result_Grid_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
RadGrid reportGrid = (RadGrid)sender;
if
(!e.IsFromDetailTable)
{
switch
(QuickReport)
{
case
QuickReportType.ByProgrammingCenter:
reportGrid.DataSource = Report.ProgrammingCenters(ReportStartDate, ReportEndDate,
true
);
RenderReportGrid(reportGrid, QuickReport);
break
;
case
QuickReportType.ByPrimaryOrganizer:
reportGrid.DataSource = Report.PrimaryOrganinizers(ReportStartDate, ReportEndDate,
true
);
RenderReportGrid(reportGrid, QuickReport);
break
;
case
QuickReportType.ByOutcomes:
reportGrid.DataSource = Report.Outcomes(ReportStartDate, ReportEndDate,
true
);
RenderReportGrid(reportGrid, QuickReport);
break
;
}
}
}
protected
void
Result_Grid_DetailTableDataBind(
object
sender, GridDetailTableDataBindEventArgs e)
{
RadGrid reportGrid = (RadGrid)sender;
GridTableView detailGrid = (GridTableView)e.DetailTableView;
//RenderDetailGrid(detailGrid, QuickReport);
GridDataItem dataItem = detailGrid.ParentItem;
switch
(QuickReport)
{
case
QuickReportType.ByProgrammingCenter:
int
departmentUnitId = (
int
)dataItem.GetDataKeyValue(
"DepartmentUnitId"
);
detailGrid.DataSource = Report.ProgramsByProgrammingCenter(departmentUnitId, ReportStartDate, ReportEndDate);
break
;
case
QuickReportType.ByPrimaryOrganizer:
string
primaryOrganizerName = dataItem.GetDataKeyValue(
"PrimaryOrganizerName"
).ToString();
int
groupId = (
int
)dataItem.GetDataKeyValue(
"GroupId"
);
detailGrid.DataSource = Report.ProgramsByPrimaryOrganizer(primaryOrganizerName, groupId, ReportStartDate, ReportEndDate);
break
;
case
QuickReportType.ByOutcomes:
int
baseOutcomeId = (
int
)dataItem.GetDataKeyValue(
"BaseOutcomeId"
);
detailGrid.DataSource = Report.ProgramsByPrimaryOutcome(baseOutcomeId, ReportStartDate, ReportEndDate);
break
;
}
}
protected
void
Result_Grid_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
if
(e.Item.OwnerTableView.Name ==
"ReportResults"
)
{
GridDataItem gridDataItem = (GridDataItem)e.Item;
int
programCount = 0;
switch
(QuickReport)
{
case
QuickReportType.ByProgrammingCenter:
string
unitName = gridDataItem[
"UnitName"
].Text;
programCount =
int
.Parse(gridDataItem[
"ProgramCount"
].Text);
if
(programCount == 1)
gridDataItem[
"UnitName"
].Text = (unitName +
" ("
+ programCount.ToString() +
" Program)"
).ToUpper();
else
gridDataItem[
"UnitName"
].Text = (unitName +
" ("
+ programCount.ToString() +
" Programs)"
).ToUpper();
gridDataItem[
"UnitName"
].Font.Bold =
true
;
gridDataItem[
"UnitName"
].HorizontalAlign = HorizontalAlign.Left;
break
;
case
QuickReportType.ByPrimaryOrganizer:
string
organizerName = gridDataItem[
"PrimaryOrganizerName"
].Text.ToString();
string
groupName = gridDataItem[
"GroupName"
].Text.ToString();
programCount =
int
.Parse(gridDataItem[
"ProgramCount"
].Text);
if
(programCount == 1)
gridDataItem[
"PrimaryOrganizerName"
].Text = (groupName +
" - "
+ organizerName +
" ("
+ programCount.ToString() +
" Program)"
).ToUpper();
else
gridDataItem[
"PrimaryOrganizerName"
].Text = (groupName +
" - "
+ organizerName +
" ("
+ programCount.ToString() +
" Programs)"
).ToUpper();
gridDataItem[
"PrimaryOrganizerName"
].Font.Bold =
true
;
gridDataItem[
"PrimaryOrganizerName"
].HorizontalAlign = HorizontalAlign.Left;
break
;
case
QuickReportType.ByOutcomes:
string
outcomeName = gridDataItem[
"PrimaryGoalName"
].Text;
programCount =
int
.Parse(gridDataItem[
"ProgramCount"
].Text);
if
(programCount == 1)
gridDataItem[
"PrimaryGoalName"
].Text = (outcomeName +
" ("
+ programCount.ToString() +
" Program)"
).ToUpper();
else
gridDataItem[
"PrimaryGoalName"
].Text = (outcomeName +
" ("
+ programCount.ToString() +
" Programs)"
).ToUpper();
gridDataItem[
"PrimaryGoalName"
].Font.Bold =
true
;
gridDataItem[
"PrimaryGoalName"
].HorizontalAlign = HorizontalAlign.Left;
break
;
}
}
}
}
#endregion
}
}
Page Code-Behind
using
System;
using
System.Web.UI.HtmlControls;
using
Telerik.Web.UI;
namespace
AZ.SA.RL.App.ProgramManagement
{
public
partial
class
ReportView : System.Web.UI.UserControl
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
Report_Toolbar_ButtonClick(
object
sender, Telerik.Web.UI.RadToolBarEventArgs e)
{
//Get clicked button information
RadToolBarButton button = (RadToolBarButton)e.Item;
string
command = button.CommandName;
string
value = button.Value;
//Determine which action to take based on the command passed by the clicked toolbar button
switch
(command)
{
case
"NEW"
:
if
(value ==
"Custom"
)
{
Report_ReportManager.DisplayMode = ProgramManagement.Controls.ReportManager.DispMode.Criteria;
Report_ReportManager.OperationMode = ProgramManagement.Controls.ReportManager.OpMode.Custom;
}
else
{
Report_ReportManager.DisplayMode = ProgramManagement.Controls.ReportManager.DispMode.Criteria;
Report_ReportManager.OperationMode = ProgramManagement.Controls.ReportManager.OpMode.Quick;
}
break
;
}
//Update the program content ajax panel
Content_AjaxPanel.Update();
}
}
}
Thanks in advance.