I have a dynamic grid which is created in page_init. The column of the grid are dynamic. Each times when i pick the new dates some blank column are added to dynamic grid. Please see attached fille.
Aspx file:
Code Behind File:
Aspx file:
<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" AutoEventWireup="true"
EnableEventValidation="false" CodeFile="HinoPartsDashboard.aspx.cs" Inherits="Dashboard_HinoPartsDashboard" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register TagPrefix="HinoDataControl" TagName="HinoDataSelect" Src="~/Components/HinoDataSelect.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
>Hino Dashboard</
title
>
<
link
rel
=
"stylesheet"
type
=
"text/css"
href
=
"../Includes/StyleSheets/Dashboard.css"
/>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
runat
=
"server"
ID
=
"RadScriptManager1"
/>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxLoadingPanel
ID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
Height
=
"75px"
Width
=
"75px"
>
<
asp:Image
ID
=
"Image1"
runat
=
"server"
AlternateText
=
"Loading..."
ImageUrl
=
"../Images/circle.gif"
/>
</
telerik:RadAjaxLoadingPanel
>
<
div
class
=
"pageheader"
>
<
h1
>
Dashboard</
h1
>
<
p
>
<
asp:Label
ID
=
"lblLastRefreshDate"
Font-Size
=
"11px"
runat
=
"Server"
Text
=
"Last Refresh Date:"
></
asp:Label
>
<
br
/>
<
a
href
=
"HinoDashboard_Main.aspx"
id
=
"backButton"
runat
=
"server"
>Dashboard Home</
a
>
</
p
>
<
a
></
a
>
</
div
>
<
div
class
=
"filters"
>
<
fieldset
>
<
legend
>Filters</
legend
>
<
dl
>
<
dt
>From Month/Year</
dt
>
<
dl
>
<
dt
>From Month</
dt
>
<
dd
>
<
asp:DropDownList
ID
=
"FromMonthDropDownList"
runat
=
"server"
AutoPostBack
=
"True"
OnSelectedIndexChanged
=
"MonthDropDownList_SelectedIndexChanged"
/>
</
dd
>
<
dt
>To Month</
dt
>
<
dd
>
<
asp:DropDownList
ID
=
"ToMonthDropDownList"
runat
=
"server"
AutoPostBack
=
"True"
OnSelectedIndexChanged
=
"MonthDropDownList_SelectedIndexChanged"
/>
</
dd
>
<
dd
class
=
"break"
>
</
dd
>
<
dd
style
=
"margin-left: 0px"
>
<
asp:CheckBox
ID
=
"chkDealer"
runat
=
"server"
Text
=
"Display By Dealers"
AutoPostBack
=
"true"
Checked
=
"true"
/></
dd
>
<
dd
style
=
"margin-left: 0px"
>
<
asp:CheckBox
ID
=
"chkVendor"
runat
=
"server"
Text
=
"Display By Vendors"
AutoPostBack
=
"true"
/></
dd
>
</
dl
>
</
fieldset
>
<
fieldset
>
<
legend
>Export Options</
legend
>
<
dl
>
<
dd
style
=
"margin-left: 0px"
>
<
asp:CheckBox
ID
=
"chk1"
Text
=
"Export only data"
runat
=
"server"
></
asp:CheckBox
></
dd
>
<
dd
style
=
"margin-left: 0px"
>
<
asp:CheckBox
ID
=
"chk4"
Text
=
"Expand Grid"
runat
=
"server"
/></
dd
>
<
dd
style
=
"margin-left: 0px"
>
<
asp:CheckBox
ID
=
"chk2"
Text
=
"Export all Pages"
runat
=
"server"
></
asp:CheckBox
></
dd
>
<
dd
style
=
"margin-left: 0px"
>
<
asp:CheckBox
ID
=
"chk3"
Text
=
"Open in new window"
runat
=
"server"
></
asp:CheckBox
></
dd
>
<
dd
style
=
"margin-left: 0px"
>
<
asp:Button
ID
=
"btnExport"
Text
=
"Export"
OnClick
=
"btnExport_Click"
runat
=
"server"
>
</
asp:Button
></
dd
>
</
dl
>
</
fieldset
>
</
div
>
<
div
class
=
"data"
style
=
"width: 60%; top: 0px; left: 0px;"
>
<
input
type
=
"hidden"
runat
=
"server"
name
=
"dist"
value
=
""
id
=
"dist"
/>
<
asp:Panel
ID
=
"pnlSalesParts"
runat
=
"server"
Width
=
"100%"
Visible
=
"true"
>
<
telerik:RadGrid
runat
=
"server"
ID
=
"rgPartDashboard"
ShowFooter
=
"true"
AllowFilteringByColumn
=
"false"
AutoGenerateColumns
=
"false"
HorizontalAlign
=
"Left"
AllowSorting
=
"false"
EnableLinqExpressions
=
"false"
PageSize
=
"10"
Width
=
"100%"
ShowGroupPanel
=
"false"
OnNeedDataSource
=
"rgPartDashboard_Load"
OnDetailTableDataBind
=
"rgPartDashboard_Detail"
ShowStatusBar
=
"true"
Skin
=
"Outlook"
AllowPaging
=
"false"
GridLines
=
"Both"
OnPreRender
=
"rgPartDashboard_PreRender"
>
<
ClientSettings
EnableRowHoverStyle
=
"true"
>
</
ClientSettings
>
<
MasterTableView
DataKeyNames
=
"user_id"
AllowMultiColumnSorting
=
"True"
HorizontalAlign
=
"Right"
Width
=
"100%"
ShowFooter
=
"true"
CssClass
=
"MasterClass"
Caption
=
"Sales 02 Parts"
>
<
DetailTables
>
<
telerik:GridTableView
Name
=
"Dealers"
AutoGenerateColumns
=
"false"
DataKeyNames
=
"dealer_id"
AllowFilteringByColumn
=
"false"
AllowSorting
=
"false"
AllowPaging
=
"false"
Width
=
"100%"
ShowFooter
=
"true"
ShowHeader
=
"false"
DataSourceID
=
"SqlDataSource2"
HorizontalAlign
=
"Right"
CssClass
=
"DetailClass"
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"DealerName"
HeaderText
=
"DealerName"
DataField
=
"Dealer_Name"
UniqueName
=
"Dealer_Name"
ItemStyle-Width
=
"225px"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
Aggregate
=
"Sum"
DataField
=
"HO_sales"
UniqueName
=
"HO_sales"
ItemStyle-Width
=
"70px"
HeaderStyle-Font-Bold
=
"true"
FooterAggregateFormatString
=
"{0:F2}"
FooterStyle-Font-Bold
=
"true"
>
<
HeaderTemplate
>
HO Sales
</
HeaderTemplate
>
<
ItemTemplate
>
<
a
href
=
"HinoPartsDashBoardTransactions.aspx?TransType=S&type=Dealer&SalesType=HO&_name=<%#GetDPMPlusDealer(Eval("
DPM_Name").ToString(),Eval("Dealer_Name").ToString())%>&DPM=<%#Eval("User_ID")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DealerID=<%#Eval("Dealer_ID")%>">
<%#Eval("HO_sales")%></
a
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
Aggregate
=
"Sum"
DataField
=
"HO_Goal"
UniqueName
=
"HO_Goal"
ItemStyle-Width
=
"70px"
HeaderStyle-Font-Bold
=
"true"
FooterAggregateFormatString
=
"{0:F2}"
FooterStyle-Font-Bold
=
"true"
>
<
HeaderTemplate
>
HO_Goal
</
HeaderTemplate
>
<
ItemTemplate
>
<
a
href
=
"HinoPartsDashBoardTransactions.aspx?TransType=G&type=Dealer&SalesType=HO&_name=<%#GetDPMPlusDealer(Eval("
DPM_Name").ToString(),Eval("Dealer_Name").ToString())%>&DPM=<%#Eval("User_ID")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DealerId=<%#Eval("Dealer_ID")%>">
<%#Eval("HO_Goal")%></
a
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridCalculatedColumn
HeaderText
=
"HO sales Effectiveness"
UniqueName
=
"HOSalesEffectiveness"
DataType
=
"System.Double"
DataFields
=
"HO_Sales, HO_Goal"
Expression
=
"iif({0}=null or {0}=0.00 or {1}=null or {1}=0.00,0.00,({0}/{1})*100)"
ItemStyle-Width
=
"95px"
DataFormatString
=
"{0:F2}%"
/>
<
telerik:GridTemplateColumn
Aggregate
=
"Sum"
DataField
=
"AM_Sales"
UniqueName
=
"AM_Sales"
ItemStyle-Width
=
"70px"
HeaderStyle-Font-Bold
=
"true"
FooterAggregateFormatString
=
"{0:F2}"
FooterStyle-Font-Bold
=
"true"
>
<
HeaderTemplate
>
AM sales
</
HeaderTemplate
>
<
ItemTemplate
>
<
a
href
=
"HinoPartsDashBoardTransactions.aspx?TransType=S&type=Dealer&SalesType=AM&_name=<%#GetDPMPlusDealer(Eval("
DPM_Name").ToString(),Eval("Dealer_Name").ToString())%>&DPM=<%#Eval("User_ID")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DealerId=<%#Eval("Dealer_ID")%>">
<%#Eval("AM_Sales")%></
a
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
Aggregate
=
"Sum"
DataField
=
"AM_GOAL"
UniqueName
=
"AM_GOAL"
ItemStyle-Width
=
"65px"
HeaderStyle-Font-Bold
=
"true"
FooterAggregateFormatString
=
"{0:F2}"
FooterStyle-Font-Bold
=
"true"
>
<
HeaderTemplate
>
AM Goal
</
HeaderTemplate
>
<
ItemTemplate
>
<
a
href
=
"HinoPartsDashBoardTransactions.aspx?TransType=G&type=Dealer&SalesType=AM&_name=<%#GetDPMPlusDealer(Eval("
DPM_Name").ToString(),Eval("Dealer_Name").ToString())%>&DPM=<%#Eval("User_ID")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DealerId=<%#Eval("Dealer_ID")%>">
<%#Eval("AM_GOAL")%></
a
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridCalculatedColumn
HeaderText
=
"AM Sales Effectiveness"
UniqueName
=
"AMEffectiveness"
DataType
=
"System.Double"
DataFields
=
"AM_Sales, AM_Goal"
Expression
=
"iif({0}=null or {0}=0.00 or {1}=null or {1}=0.00,0.00,({0}/{1})*100)"
ItemStyle-Width
=
"90px"
DataFormatString
=
"{0:F2}%"
/>
<
telerik:GridTemplateColumn
Aggregate
=
"Sum"
DataField
=
"Total_Sales"
UniqueName
=
"Total_Sales"
ItemStyle-Width
=
"70px"
HeaderStyle-Font-Bold
=
"true"
FooterAggregateFormatString
=
"{0:F2}"
FooterStyle-Font-Bold
=
"true"
>
<
HeaderTemplate
>
Total Sales
</
HeaderTemplate
>
<
ItemTemplate
>
<
a
href
=
"HinoPartsDashBoardTransactions.aspx?TransType=S&type=Dealer&SalesType=T&_name=<%#GetDPMPlusDealer(Eval("
DPM_Name").ToString(),Eval("Dealer_Name").ToString())%>&DPM=<%#Eval("User_ID")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DealerId=<%#Eval("Dealer_ID")%>">
<%#Eval("Total_Sales")%></
a
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
Aggregate
=
"Sum"
DataField
=
"Total_Goal"
UniqueName
=
"Total_Goal"
ItemStyle-Width
=
"70px"
HeaderStyle-Font-Bold
=
"true"
FooterAggregateFormatString
=
"{0:F2}"
FooterStyle-Font-Bold
=
"true"
>
<
HeaderTemplate
>
Total Goal
</
HeaderTemplate
>
<
ItemTemplate
>
<
a
href
=
"HinoPartsDashBoardTransactions.aspx?TransType=G&type=Dealer&SalesType=T&_name=<%#GetDPMPlusDealer(Eval("
DPM_Name").ToString(),Eval("Dealer_Name").ToString())%>&DPM=<%#Eval("User_ID")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DealerId=<%#Eval("Dealer_ID")%>">
<%#Eval("Total_Goal")%></
a
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridCalculatedColumn
HeaderText
=
"Total Sales Effectiveness"
UniqueName
=
"TotalEffectiveness"
DataType
=
"System.Double"
DataFields
=
"Total_Sales,Total_goal"
Expression
=
"iif({0}=null or {0}=0.00 or {1}=null or {1}=0.00,0.00,({0}/{1})*100)"
ItemStyle-Width
=
"90px"
DataFormatString="{0:F2}%</a>" />
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"DPM_Name"
HeaderText
=
"DPM"
DataField
=
"DPM_Name"
HeaderStyle-Font-Bold
=
"true"
UniqueName
=
"DPM_Name"
ItemStyle-Width
=
"280px"
FooterText
=
"Grand Total:"
FooterStyle-Font-Bold
=
"true"
ItemStyle-Font-Bold
=
"true"
ItemStyle-Font-Size
=
"Medium"
ItemStyle-ForeColor
=
"Blue"
ItemStyle-BackColor
=
"Beige"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
Aggregate
=
"Sum"
DataField
=
"HO_sales"
UniqueName
=
"HO_sales"
ItemStyle-Width
=
"75px"
HeaderStyle-Font-Bold
=
"true"
FooterAggregateFormatString
=
"{0:F2}"
FooterStyle-Font-Bold
=
"true"
>
<
HeaderTemplate
>
HO Sales
</
HeaderTemplate
>
<
ItemTemplate
>
<
a
href
=
"HinoPartsDashBoardTransactions.aspx?TransType=S&type=DPM&SalesType=HO&_name=<%#Eval("
DPM_Name")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DPM=<%#Eval("User_ID")%>">
<%#Eval("HO_sales")%></
a
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
Aggregate
=
"Sum"
DataField
=
"HO_Goal"
UniqueName
=
"HO_Goal"
ItemStyle-Width
=
"75px"
HeaderStyle-Font-Bold
=
"true"
FooterAggregateFormatString
=
"{0:F2}"
FooterStyle-Font-Bold
=
"true"
>
<
HeaderTemplate
>
HO Goal
</
HeaderTemplate
>
<
ItemTemplate
>
<
a
href
=
"HinoPartsDashBoardTransactions.aspx?TransType=G&type=DPM&SalesType=HO&_name=<%#Eval("
DPM_Name")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DPM=<%#Eval("User_ID")%>">
<%#Eval("HO_Goal")%></
a
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridCalculatedColumn
Aggregate
=
"Avg"
ItemStyle-Width
=
"100px"
HeaderText
=
"HO Sales Effectiveness"
UniqueName
=
"HoSalesEffectiveness"
HeaderStyle-Font-Bold
=
"true"
FooterAggregateFormatString
=
"{0:F2}%"
FooterStyle-Font-Bold
=
"true"
DataType
=
"System.Double"
DataFields
=
"HO_Sales, HO_Goal"
Expression
=
"iif({0}=null or {0}=0.00 or {1}=null or {1}=0.00,0.00,({0}/{1})*100)"
DataFormatString
=
"{0:F2}%"
>
</
telerik:GridCalculatedColumn
>
<
telerik:GridTemplateColumn
Aggregate
=
"Sum"
DataField
=
"AM_sales"
UniqueName
=
"AM_sales"
ItemStyle-Width
=
"75px"
HeaderStyle-Font-Bold
=
"true"
FooterAggregateFormatString
=
"{0:F2}"
FooterStyle-Font-Bold
=
"true"
>
<
HeaderTemplate
>
AM Sales
</
HeaderTemplate
>
<
ItemTemplate
>
<
a
href
=
"HinoPartsDashBoardTransactions.aspx?TransType=S&type=DPM&SalesType=AM&_name=<%#Eval("
DPM_Name")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DPM=<%#Eval("User_ID")%>">
<%#Eval("AM_sales")%></
a
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
Aggregate
=
"Sum"
DataField
=
"AM_GOAL"
UniqueName
=
"AM_GOAL"
ItemStyle-Width
=
"75px"
HeaderStyle-Font-Bold
=
"true"
FooterAggregateFormatString
=
"{0:F2}"
FooterStyle-Font-Bold
=
"true"
>
<
HeaderTemplate
>
AM Goal
</
HeaderTemplate
>
<
ItemTemplate
>
<
a
href
=
"HinoPartsDashBoardTransactions.aspx?TransType=G&type=DPM&SalesType=AM&_name=<%#Eval("
DPM_Name")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DPM=<%#Eval("User_ID")%>">
<%#Eval("AM_GOAL")%></
a
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridCalculatedColumn
ItemStyle-Width
=
"100px"
HeaderText
=
"AM Sales Effectiveness"
UniqueName
=
"AMEffectiveness"
HeaderStyle-Font-Bold
=
"true"
DataType
=
"System.Double"
DataFields
=
"AM_Sales, AM_Goal"
Expression
=
"iif({0}=null or {0}=0.00 or {1}=null or {1}=0.00,0.00,({0}/{1})*100)"
DataFormatString
=
"{0:F2}%"
FooterAggregateFormatString
=
"{0:F2}%"
Aggregate
=
"Avg"
FooterStyle-Font-Bold
=
"true"
/>
<
telerik:GridTemplateColumn
Aggregate
=
"Sum"
DataField
=
"Total_sales"
UniqueName
=
"Total_sales"
ItemStyle-Width
=
"75px"
HeaderStyle-Font-Bold
=
"true"
FooterAggregateFormatString
=
"{0:F2}"
FooterStyle-Font-Bold
=
"true"
>
<
HeaderTemplate
>
Total sales
</
HeaderTemplate
>
<
ItemTemplate
>
<
a
href
=
"HinoPartsDashBoardTransactions.aspx?TransType=S&type=DPM&SalesType=T&_name=<%#Eval("
DPM_Name")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DPM=<%#Eval("User_ID")%>">
<%#Eval("Total_sales")%></
a
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
Aggregate
=
"Sum"
DataType
=
"System.Decimal"
DataField
=
"Total_Goal"
UniqueName
=
"TotalGoals"
ItemStyle-Width
=
"75px"
HeaderStyle-Font-Bold
=
"true"
FooterAggregateFormatString
=
"{0:F2}"
FooterStyle-Font-Bold
=
"true"
>
<
HeaderTemplate
>
Total Goal
</
HeaderTemplate
>
<
ItemTemplate
>
<
a
href
=
"HinoPartsDashBoardTransactions.aspx?TransType=G&type=DPM&SalesType=T&_name=<%#Eval("
DPM_Name")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DMP=<%#Eval("User_ID")%>">
<%#Eval("Total_Goal")%></
a
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridCalculatedColumn
ItemStyle-Width
=
"100px"
HeaderText
=
"Total Sales Effectiveness"
HeaderStyle-Font-Bold
=
"true"
UniqueName
=
"TotalEffectivenessabc"
DataType
=
"System.Double"
DataFields
=
"Total_sales,Total_Goal"
Expression
=
"iif({0}=null or {0}=0.00 or {1}=0.00,0.00,({0}/{1})*100)"
DataFormatString
=
"{0:F2}%"
FooterAggregateFormatString
=
"{0:F2}%"
Aggregate
=
"Avg"
FooterStyle-Font-Bold
=
"true"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
asp:Panel
>
<
asp:SqlDataSource
ID
=
"SqlDataSource3"
ConnectionString="<%$ ConnectionStrings:HinoConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommandType="StoredProcedure" SelectCommand="spSelectPartsDashboardSalesByDPM_ForDateRange"
runat="server">
<
SelectParameters
>
<
asp:SessionParameter
Name
=
"StartMonth"
SessionField
=
"StartMonth"
Type
=
"Int32"
DefaultValue
=
"01"
/>
<
asp:SessionParameter
Name
=
"StartYear"
SessionField
=
"StartYear"
Type
=
"Int32"
DefaultValue
=
"2012"
/>
<
asp:SessionParameter
Name
=
"EndMonth"
SessionField
=
"EndMonth"
Type
=
"Int32"
DefaultValue
=
"01"
/>
<
asp:SessionParameter
Name
=
"EndYear"
SessionField
=
"EndYear"
Type
=
"Int32"
DefaultValue
=
"2013"
/>
</
SelectParameters
>
</
asp:SqlDataSource
>
<
asp:SqlDataSource
ID
=
"SqlDataSource2"
ConnectionString="<%$ ConnectionStrings:HinoConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommandType="StoredProcedure" SelectCommand="spSelectPartsDashboardSalesByOneDPM_ForDateRange"
runat="server">
<
SelectParameters
>
<
asp:SessionParameter
Name
=
"Userid"
SessionField
=
"Userid"
Type
=
"Int32"
DefaultValue
=
"2568"
/>
<
asp:SessionParameter
Name
=
"StartMonth"
SessionField
=
"StartMonth"
Type
=
"Int32"
DefaultValue
=
"01"
/>
<
asp:SessionParameter
Name
=
"StartYear"
SessionField
=
"StartYear"
Type
=
"Int32"
DefaultValue
=
"2012"
/>
<
asp:SessionParameter
Name
=
"EndMonth"
SessionField
=
"EndMonth"
Type
=
"Int32"
DefaultValue
=
"01"
/>
<
asp:SessionParameter
Name
=
"EndYear"
SessionField
=
"EndYear"
Type
=
"Int32"
DefaultValue
=
"2013"
/>
</
SelectParameters
>
</
asp:SqlDataSource
>
<
asp:Panel
ID
=
"pnlSalesByVendor"
runat
=
"server"
Width
=
"100%"
Visible
=
"false"
>
</
asp:Panel
>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
ConnectionString="<%$ ConnectionStrings:HinoConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommandType="StoredProcedure" SelectCommand="spSelectPartsDashboardSalesByVendor_ForDateRange"
runat="server">
<
SelectParameters
>
<
asp:SessionParameter
Name
=
"StartMonth"
SessionField
=
"StartMonth"
Type
=
"Int32"
DefaultValue
=
"01"
/>
<
asp:SessionParameter
Name
=
"StartYear"
SessionField
=
"StartYear"
Type
=
"Int32"
DefaultValue
=
"2012"
/>
<
asp:SessionParameter
Name
=
"EndMonth"
SessionField
=
"EndMonth"
Type
=
"Int32"
DefaultValue
=
"05"
/>
<
asp:SessionParameter
Name
=
"EndYear"
SessionField
=
"EndYear"
Type
=
"Int32"
DefaultValue
=
"2013"
/>
</
SelectParameters
>
</
asp:SqlDataSource
>
</
div
>
</
form
>
</
body
>
</
html
>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Hino_BL;
using Telerik.Web.UI;
public partial class Dashboard_HinoPartsDashboard : System.Web.UI.Page
{
#region Properties
private int _LoggedInUser;
private string _LoggedInUserName;
private int _SecurityPage;
private bool _IsAdmin;
public int LoggedInUser
{
get { return _LoggedInUser; }
set { _LoggedInUser = value; }
}
public string LoggedInUserName
{
get { return _LoggedInUserName; }
set { _LoggedInUserName = value; }
}
public int SecurityPage
{
get { return _SecurityPage; }
set { _SecurityPage = value; }
}
public bool IsAdmin
{
get { return _IsAdmin; }
set { _IsAdmin = value; }
}
#endregion
protected void rgPartDashboard_PreRender(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//rgPartDashboard.MasterTableView.Items[0].Expanded = true;
//rgDashboard.MasterTableView.Items[0].ChildItem.FindControl("InnerContainer").Visible = true;
}
}
private void DefineGridStructure()
{
try
{
string FromYearMonth = Request.Form.Get("FromMonthDropDownList");
string ToYearMonth = Request.Form.Get("ToMonthDropDownList");
if (FromYearMonth == null)
{
FromYearMonth = FromMonthDropDownList.SelectedValue;
ToYearMonth = ToMonthDropDownList.SelectedValue;
}
RadGrid rgPartSalesByVendor = new RadGrid();
rgPartSalesByVendor.AutoGenerateColumns = false;
rgPartSalesByVendor.ID = "rgPartSalesByVendor";
rgPartSalesByVendor.GridLines = System.Web.UI.WebControls.GridLines.Both;
rgPartSalesByVendor.ShowFooter = true;
rgPartSalesByVendor.Skin = "Outlook";
rgPartSalesByVendor.NeedDataSource += new Telerik.Web.UI.GridNeedDataSourceEventHandler(rgPartSalesByVendor_Load);
rgPartSalesByVendor.MasterTableView.Caption = "Sales By Vendor";
rgPartSalesByVendor.MasterTableView.CssClass = "MasterClass";
rgPartSalesByVendor.MasterTableView.Columns.Clear();
GridBoundColumn boundColumnVendor = new GridBoundColumn();
boundColumnVendor.DataField = "Vendor";
boundColumnVendor.UniqueName = "Vendor";
boundColumnVendor.HeaderText = "Vendor";
boundColumnVendor.HeaderStyle.Font.Bold = true;
boundColumnVendor.FooterStyle.Font.Bold = true;
boundColumnVendor.FooterText = "Grand Total:";
boundColumnVendor.ItemStyle.ForeColor = System.Drawing.Color.Blue;
rgPartSalesByVendor.MasterTableView.Columns.Add(boundColumnVendor);
//Bind sales By vendor Grid
SqlDataSource1.SelectParameters["StartMonth"].DefaultValue = FromYearMonth.Substring(4, 2);
SqlDataSource1.SelectParameters["StartYear"].DefaultValue = FromYearMonth.Substring(0, 4);
SqlDataSource1.SelectParameters["EndMonth"].DefaultValue = ToYearMonth.Substring(4, 2);
SqlDataSource1.SelectParameters["EndYear"].DefaultValue = ToYearMonth.Substring(0, 4);
DataTable dt = null;
DataView dv = null;
dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
if (dv != null)
{
dt = dv.ToTable();
CreateTemplateColumn(dt, ref rgPartSalesByVendor, FromYearMonth, ToYearMonth);
}
pnlSalesByVendor.Controls.Add(rgPartSalesByVendor);
Session.Add("GridPartSalesByVendor", rgPartSalesByVendor);
}
catch (Exception e)
{
Response.Write("Error has occured in DefineGrid structure" + e.Message);
}
}
protected void Page_Init(object sender, EventArgs e)
{
if (!IsPostBack)
{
InitializeMonthDropDownLists();
}
DefineGridStructure();
}
protected void Page_Load(object sender, EventArgs e)
{
//get the logged in user
//this will work on local dev machine and prod without a change
if (Request.Url.AbsoluteUri.ToString().Contains("localhost"))
LoggedInUserName = "bbajwa";
//LoggedInUserName = "braddpm";
else
LoggedInUserName = Request.Cookies["UserName"].Value.ToString();
//verify that they can access this page.
check_Security();
if (!IsPostBack)
{
try
{
Hino_BL.HinoCommons getRefresh = new Hino_BL.HinoCommons();
lblLastRefreshDate.Text = "Last Refresh Date: " + Convert.ToDateTime(getRefresh.GetConfigVariableFromDatabase("AS400", "LastDashboardRefreshDate")[0].VariableValue.ToString());
}
catch
{
lblLastRefreshDate.Text = "Last Refresh Date: N/A";
}
}
try
{
RadGrid grid = (RadGrid)pnlSalesByVendor.FindControl("rgPartSalesByVendor");
RadAjaxManager1.AjaxSettings.Clear();
RadAjaxManager1.AjaxSettings.AddAjaxSetting(FromMonthDropDownList, pnlSalesByVendor, RadAjaxLoadingPanel1);
RadAjaxManager1.AjaxSettings.AddAjaxSetting(FromMonthDropDownList, pnlSalesParts, RadAjaxLoadingPanel1);
RadAjaxManager1.AjaxSettings.AddAjaxSetting(FromMonthDropDownList, grid, RadAjaxLoadingPanel1);
}
catch (Exception ex)
{
Response.Write("Error has occured in updating Ajax" + ex.Message);
}
if (chkVendor.Checked)
{
pnlSalesParts.Visible = false;
pnlSalesByVendor.Visible = true;
}
if (chkDealer.Checked || (chkDealer.Checked & chkVendor.Checked))
{
pnlSalesParts.Visible = true;
pnlSalesByVendor.Visible = false;
}
if (!chkDealer.Checked & !chkVendor.Checked)
{
pnlSalesParts.Visible = true;
pnlSalesByVendor.Visible = false;
}
}
public void InitializeMonthDropDownLists()
{
Int32 offset = -12;
while (offset <= 0)
{
FromMonthDropDownList.Items.Add(new ListItem(string.Format("{0:MMMM} {0:yyyy}", DateTime.Today.AddMonths(offset)), string.Format("{0:yyyy}{0:MM}", DateTime.Today.AddMonths(offset))));
ToMonthDropDownList.Items.Add(new ListItem(string.Format("{0:MMMM} {0:yyyy}", DateTime.Today.AddMonths(offset)), string.Format("{0:yyyy}{0:MM}", DateTime.Today.AddMonths(offset))));
offset += 1;
}
try
{
if (Session["FromMonth"].ToString() != "")
{
FromMonthDropDownList.Items.FindByValue(Session["FromMonth"].ToString()).Selected = true;
}
else
{
FromMonthDropDownList.SelectedIndex = 12;
}
if (Session["ToMonth"].ToString() != "")
{
ToMonthDropDownList.Items.FindByValue(Session["ToMonth"].ToString()).Selected = true;
}
else
{
ToMonthDropDownList.SelectedIndex = 12;
}
}
catch
{
FromMonthDropDownList.SelectedIndex = 12;
ToMonthDropDownList.SelectedIndex = 12;
}
}
protected void MonthDropDownList_SelectedIndexChanged(object source, EventArgs e)
{
string FromYearMonth = FromMonthDropDownList.SelectedValue;
string ToYearMonth = ToMonthDropDownList.SelectedValue;
try
{
SqlDataSource3.SelectParameters["StartMonth"].DefaultValue = FromYearMonth.Substring(4, 2);
SqlDataSource3.SelectParameters["StartYear"].DefaultValue = FromYearMonth.Substring(0, 4);
SqlDataSource3.SelectParameters["EndMonth"].DefaultValue = ToYearMonth.Substring(4, 2);
SqlDataSource3.SelectParameters["EndYear"].DefaultValue = ToYearMonth.Substring(0, 4);
rgPartDashboard.DataSource = SqlDataSource3;
//Bind sales By vendor Grid
SqlDataSource1.SelectParameters["StartMonth"].DefaultValue = FromYearMonth.Substring(4, 2);
SqlDataSource1.SelectParameters["StartYear"].DefaultValue = FromYearMonth.Substring(0, 4);
SqlDataSource1.SelectParameters["EndMonth"].DefaultValue = ToYearMonth.Substring(4, 2);
SqlDataSource1.SelectParameters["EndYear"].DefaultValue = ToYearMonth.Substring(0, 4);
RadGrid grid = (RadGrid)pnlSalesByVendor.FindControl("rgPartSalesByVendor");
grid.DataSource = SqlDataSource1;
grid.Rebind();
}
catch (Exception ex)
{
Response.Write("Error has occured:" + ex.Message);
}
Session.Add("FromMonth", FromMonthDropDownList.SelectedValue);
Session.Add("ToMonth", ToMonthDropDownList.SelectedValue);
if (rgPartDashboard.Visible)
{
rgPartDashboard.Rebind();
}
}
protected void btnExport_Click(object sender, System.EventArgs e)
{
RadGrid grid = (RadGrid)pnlSalesByVendor.FindControl("rgPartSalesByVendor");
if (grid.Visible)
{
grid.MasterTableView.ExportToExcel();
}
if (rgPartDashboard.Visible)
{
ConfigureExport();
rgPartDashboard.MasterTableView.ExportToExcel();
}
}
public void ConfigureExport()
{
rgPartDashboard.ExportSettings.ExportOnlyData = chk1.Checked;
rgPartDashboard.ExportSettings.IgnorePaging = chk2.Checked;
rgPartDashboard.ExportSettings.OpenInNewWindow = chk3.Checked;
if (chk4.Checked)
{
rgPartDashboard.ExportSettings.IgnorePaging = false;
foreach (Telerik.Web.UI.GridDataItem item in rgPartDashboard.MasterTableView.Items)
{
item.Expanded = true;
foreach (Telerik.Web.UI.GridDataItem nestedItem in item.ChildItem.NestedTableViews[0].Items)
{
nestedItem.Expanded = true;
//foreach (Telerik.Web.UI.GridDataItem nestedItem1 in nestedItem.ChildItem.NestedTableViews[0].Items)
//{
// nestedItem1.Expanded = true;
//}
}
}
}
}
protected void rgPartDashboard_Load(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
if (!e.IsFromDetailTable)
{
string FromYearMonth = FromMonthDropDownList.SelectedValue;
string ToYearMonth = ToMonthDropDownList.SelectedValue;
try
{
SqlDataSource3.SelectParameters["StartMonth"].DefaultValue = FromYearMonth.Substring(4, 2);
SqlDataSource3.SelectParameters["StartYear"].DefaultValue = FromYearMonth.Substring(0, 4);
SqlDataSource3.SelectParameters["EndMonth"].DefaultValue = ToYearMonth.Substring(4, 2);
SqlDataSource3.SelectParameters["EndYear"].DefaultValue = ToYearMonth.Substring(0, 4);
rgPartDashboard.DataSource = SqlDataSource3;
}
catch (Exception ex)
{
Response.Write("Error has occured in rgPartDashboard_Load" + ex.Message);
}
}
}
protected void rgPartDashboard_Detail(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
{
string FromYearMonth = FromMonthDropDownList.SelectedValue;
string ToYearMonth = ToMonthDropDownList.SelectedValue;
try
{
Telerik.Web.UI.GridDataItem dataItem = (Telerik.Web.UI.GridDataItem)e.DetailTableView.ParentItem;
SqlDataSource2.SelectParameters["userid"].DefaultValue = dataItem.GetDataKeyValue("user_id").ToString();
SqlDataSource2.SelectParameters["StartMonth"].DefaultValue = FromYearMonth.Substring(4, 2);
SqlDataSource2.SelectParameters["StartYear"].DefaultValue = FromYearMonth.Substring(0, 4);
SqlDataSource2.SelectParameters["EndMonth"].DefaultValue = ToYearMonth.Substring(4, 2);
SqlDataSource2.SelectParameters["EndYear"].DefaultValue = ToYearMonth.Substring(0, 4);
(source as Telerik.Web.UI.RadGrid).DataSource = SqlDataSource2;
}
catch (Exception ex)
{
Response.Write("Error has occured in rgPartDashboard_Detail:" + ex.Message);
}
}
protected string GetDPMPlusDealer(string DMPName, string DealerName)
{
return DMPName + ", " + DealerName;
}
protected void rgPartSalesByVendor_Load(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
if (!e.IsFromDetailTable)
{
string FromYearMonth = FromMonthDropDownList.SelectedValue;
string ToYearMonth = ToMonthDropDownList.SelectedValue;
try
{
SqlDataSource1.SelectParameters["StartMonth"].DefaultValue = FromYearMonth.Substring(4, 2);
SqlDataSource1.SelectParameters["StartYear"].DefaultValue = FromYearMonth.Substring(0, 4);
SqlDataSource1.SelectParameters["EndMonth"].DefaultValue = ToYearMonth.Substring(4, 2);
SqlDataSource1.SelectParameters["EndYear"].DefaultValue = ToYearMonth.Substring(0, 4);
(source as Telerik.Web.UI.RadGrid).DataSource = SqlDataSource1;
}
catch (Exception ex)
{
Response.Write("Error has occured in rgPartSalesByVendor_Load:" + ex.Message);
}
}
}
#region Create GridTemplate column
private void CreateTemplateColumn(DataTable dt, ref RadGrid rg, string FromYearMonth, string ToYearMonth)
{
foreach (DataColumn dc in dt.Columns)
{
if (dc.ColumnName == "Vendor" || dc.ColumnName == "vendorID")
continue;
if (dc.ColumnName != "Vendor" && dc.ColumnName != "VendorID")
{
string ColName = dc.ColumnName;
string[] DPMNameAndID = ColName.Split(';');
string DPMName = DPMNameAndID[0];
string DMPId = DPMNameAndID[1];
GridTemplateColumn templateColumn = new GridTemplateColumn();
templateColumn.ItemTemplate = new MyTemplate(ColName, FromYearMonth, ToYearMonth, DPMName, DMPId);
templateColumn.SortExpression = ColName;
templateColumn.HeaderText = DPMName;
templateColumn.HeaderStyle.Font.Bold = true;
templateColumn.FooterStyle.Font.Bold = true;
templateColumn.FooterAggregateFormatString = "{0:F2}";
templateColumn.DataField = ColName;
templateColumn.Aggregate = Telerik.Web.UI.GridAggregateFunction.Sum;
rg.MasterTableView.Columns.Add(templateColumn);
}
}
}
private class MyTemplate : ITemplate
{
protected HyperLink SealeByVendorTrans;
private string colname;
private string _fromDate;
private string _toDate;
private string _DPMName;
private string _DPMId;
public MyTemplate(string cName, string fromDate, string toDate, string DPMName, string DPMId)
{
colname = cName;
_fromDate = fromDate;
_toDate = toDate;
_DPMName = DPMName;
_DPMId = DPMId;
}
public void InstantiateIn(System.Web.UI.Control container)
{
SealeByVendorTrans = new HyperLink();
SealeByVendorTrans.ID = colname;
SealeByVendorTrans.DataBinding += new EventHandler(SealeByVendorTrans_DataBinding);
container.Controls.Add(SealeByVendorTrans);
}
void SealeByVendorTrans_DataBinding(object sender, EventArgs e)
{
HyperLink link = (HyperLink)sender;
GridDataItem container = (GridDataItem)link.NamingContainer;
link.Text = ((DataRowView)container.DataItem)[colname].ToString();
link.NavigateUrl = "HinoPartsDashBoardTransactions.aspx?type=Vendor&TransType=V&DPMName=" + _DPMName + "&DPM=" + _DPMId + "&from=" + _fromDate + "&to=" + _toDate + "&VendorID=" + ((DataRowView)container.DataItem)["VendorID"].ToString() + "&Vendor=" + ((DataRowView)container.DataItem)["Vendor"].ToString();
}
}
#endregion
#region Security
public void check_Security()
{
Boolean HasAccess = false;
IsAdmin = false;
Hino_BL.UserSecurity userSec = new Hino_BL.UserSecurity();
userSec.UserName = LoggedInUserName;
try
{
UserSecurity userInfo = userSec.GetUserByUserName()[0];
LoggedInUser = userInfo.User_id;
}
catch
{
LoggedInUser = 0;
}
userSec.SecurityPageName = "Dashboard";
foreach (UserSecurity list in userSec.GetSecurityPageByName())
{
SecurityPage = list.SecurityPage_id;
}
userSec.SecurityPage_id = _SecurityPage;
userSec.User_id = _LoggedInUser;
foreach (UserSecurity list in userSec.GetSecurityFunctionsByUser_idandSecurityPage_id())
{
HasAccess = true;
}
//if they don't have access take them to the access denied page.
if (!HasAccess)
{
Response.Redirect("../AccessDenied.aspx");
}
}
#endregion
}