Basically i am using a custom user control named DashboardGrid. We can specify database name adn query in it and the grid gets populated.
.ascx
the code behind has following important method (I can not post the whole code but trying post just the relevant)
C# code behind (.ascx.cs)
Below are my sorting and paging event handlers for the RadGrid:
Following is the way I am deploying the control:
MY QUESTION IS, IF I USE THIS USER CONTROL JUST ONE TIME IT WORKS FINE BUT IF I USE THE SAME CONTROL THE VERY NEXT TIME THAN PAGING/SORTING WILL THROW THIS json ERROR.
AS I HAVE THE PAGING FOOTER I DO SEE PAGE x OF y, ITEMS p TO q OF r - CORRECTLY
.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DashBoardGrid.ascx.cs"
Inherits="WebUserControlTest.WebUserControl1" %>
<
script
type
=
"text/javascript"
>
function pageLoad(sender, eventArgs)
{
}
</
script
>
<
telerik:RadGrid
ID
=
"DashboardGrid"
runat
=
"server"
PageSize
=
"8"
AllowPaging
=
"true"
Width
=
"60%"
PagerStyle-AlwaysVisible
=
"false"
AllowFilteringByColumn
=
"True"
AllowSorting
=
"True"
OnNeedDataSource
=
"DashGrid_NeedDataSource"
CellSpacing
=
"1"
OnPageIndexChanged
=
"DashboardGrid_PagingCommand"
GridLines
=
"None"
OnSortCommand
=
"DashboardGrid_SortCommand"
PagerStyle-Mode
=
"NextPrev"
ClientIDMode
=
"Static"
GroupingEnabled
=
"False"
OnSelectedCellChanged
=
"DashboardGrid_SelectedCellChanged1"
PagerStyle-HorizontalAlign
=
"Center"
PagerStyle-VerticalAlign
=
"Middle"
SelectedItemStyle-VerticalAlign
=
"Top"
MasterTableView-PageSize
=
"8"
>
<
MasterTableView
AllowMultiColumnSorting
=
"true"
TableLayout
=
"Fixed"
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
></
CommandItemSettings
>
<
RowIndicatorColumn
Visible
=
"True"
FilterControlAltText
=
"Filter RowIndicator column"
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
Visible
=
"True"
FilterControlAltText
=
"Filter ExpandColumn column"
>
</
ExpandCollapseColumn
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
>
</
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
<
FilterMenu
EnableImageSprites
=
"False"
>
</
FilterMenu
>
</
telerik:RadGrid
>
the code behind has following important method (I can not post the whole code but trying post just the relevant)
C# code behind (.ascx.cs)
string QueryOrStoredProcedure, bool HasStoredProcedure and int DatabaseEnum are public properties (of the custom user
control)
PAGE_LOAD :
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { LoadData(); //DashboardGrid.ClientSettings.DataBinding.EnableCaching = true; DashboardGrid.DataBind(); } }
string
ConnectionString =
string
.Empty;
string
SelectQuery =
string
.Empty;
if
(!HasStoredProcedure)
SelectQuery = QueryOrStoredProcedure;
ConnectionStringSettingsCollection ConnctionStringCollection = ConfigurationManager.ConnectionStrings;
if
(ConnctionStringCollection !=
null
)
{
foreach
(ConnectionStringSettings connection
in
ConnctionStringCollection)
{
if
(
string
.Equals(connection.Name,
"LocalConnectionString"
))
{
ConnectionString = connection.ConnectionString;
if
(!
string
.IsNullOrEmpty(DB 1) && !
string
.IsNullOrEmpty(DB 2) && !
string
.IsNullOrEmpty(DB 3) && !
string
.IsNullOrEmpty(DB 4) && !
string
.IsNullOrEmpty(DB 5) && ConnectionString.Contains(
"master"
))
{
switch
(DatabaseEnum)
{
case
1:
ConnectionString = ConnectionString.Replace(
"master"
, DB 1);
break
;
case
2:
ConnectionString = ConnectionString.Replace(
"master"
, DB 2);
break
;
case
3:
ConnectionString = ConnectionString.Replace(
"master"
, DB 3);
break
;
case
4:
ConnectionString = ConnectionString.Replace(
"master"
, DB 4);
break
;
case
5:
ConnectionString = ConnectionString.Replace(
"master"
, DB 5);
break
;
default
:
ConnectionString = ConnectionString.Replace(
"master"
, DB 6);
break
;
}
}
break
;
}
}
SqlConnection Connection =
new
SqlConnection(ConnectionString);
SqlDataAdapter Adapter =
new
SqlDataAdapter();
DataSet DashboardGridDataSet =
new
DataSet();
try
{
Connection.Open();
if
(Connection.State.ToString().ToLower() ==
"open"
)
{
Adapter.SelectCommand =
new
SqlCommand(SelectQuery, Connection);
Adapter.Fill(DashboardGridDataSet);
}
}
finally
{
Connection.Close();
}
DataView DashboardGridDataView = DashboardGridDataSet.Tables[0].DefaultView;
DashboardGrid.DataSource = DashboardGridDataView;
Session[
"DashboardGridData"
] = DashboardGridDataView;
Session[
"GridPages"
] = DashboardGrid.PageCount;
}
}
Below are my sorting and paging event handlers for the RadGrid:
protected
void
DashboardGrid_PagingCommand(
object
sender, Telerik.Web.UI.GridPageChangedEventArgs e)
{
if
(e.NewPageIndex < Convert.ToInt32(Session[
"GridPages"
]) && e.NewPageIndex >= 0)
DashboardGrid.CurrentPageIndex = e.NewPageIndex;
DashboardGrid.Rebind();
}
protected
void
DashboardGrid_SortCommand(
object
sender, Telerik.Web.UI.GridSortCommandEventArgs e)
{
DataView DashGridData = Session[
"DashboardGridData"
]
as
DataView;
if
(DashGridData !=
null
)
{
DashGridData.Sort = e.SortExpression +
" "
+ GetSortDirection(e.SortExpression);
// GetSortDirection() is some function that returns ASC & DESC alternatively
DashboardGrid.DataSource = DashGridData;
DashboardGrid.Rebind();
}
}
Following is the way I am deploying the control:
<div id=
"GridShowCaseDivision"
runat=
"server"
style="width: 100%; position: absolute;
height: 100%; right: 0; top: 10">
<telerik:RadRotator ID=
"GridShowCaseRotator"
runat=
"server"
Width=
"60%"
ItemHeight=
"100%"
Height=
"35%"
WrapFrames=
"false"
ItemWidth=
"50%"
RegisterWithScriptManager=
"true"
RotatorType=
"Buttons"
Visible=
"true"
>
<Items>
<telerik:RadRotatorItem Width=
"15%"
>
<ItemTemplate>
<Dashboard:IconGrid runat=
"server"
ID=
"EventGrid"
DatabaseEnum=
"4"
HasStoredProcedure=
"false"
QueryOrStoredProcedure=
" VALID AND TESTED SQL QUERY"
/>
</ItemTemplate>
</telerik:RadRotatorItem>
</Items>
</telerik:RadRotator>
</div>
MY QUESTION IS, IF I USE THIS USER CONTROL JUST ONE TIME IT WORKS FINE BUT IF I USE THE SAME CONTROL THE VERY NEXT TIME THAN PAGING/SORTING WILL THROW THIS json ERROR.
AS I HAVE THE PAGING FOOTER I DO SEE PAGE x OF y, ITEMS p TO q OF r - CORRECTLY