Hi there,
I'm having a problem with my radrid multi-level grouping.
When a Ajax request occours my grid loses all data.
I show my source code.
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage/IAMS.Master" AutoEventWireup="true" CodeBehind="ForeCastManager.aspx.cs" Inherits="LCG.Web.IAMS.AWA.Pages.ForeCastManager" %>
<%@ Register Src="~/Controls/Common/CustomNotification.ascx" TagPrefix="common" TagName="notification" %>
<
asp:Content
ContentPlaceHolderID
=
"ContentPlaceHolder1"
runat
=
"server"
>
<
telerik:RadAjaxManager
ID
=
"ForecastAjaxManager"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"ForecastClientesRadGrid"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"TabForecastList"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"ForecastPagesViews"
LoadingPanelID
=
"TaskLoadingPanel"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"ForecastPagesViews"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"TabForecastList"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"ForecastPagesViews"
LoadingPanelID
=
"TaskLoadingPanel"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"TabForecastList"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"TabForecastList"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"ForecastPagesViews"
LoadingPanelID
=
"TaskLoadingPanel"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"ForecastAjaxManager"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"ForecastPagesViews"
LoadingPanelID
=
"TaskLoadingPanel"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"TabForecastList"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"ForecastClientesRadGrid"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxLoadingPanel
runat
=
"server"
ID
=
"TaskLoadingPanel"
>
</
telerik:RadAjaxLoadingPanel
>
</
asp:Content
>
<
asp:Content
ContentPlaceHolderID
=
"ContentPlaceHolder2"
runat
=
"server"
>
<
telerik:RadMenu
runat
=
"server"
ID
=
"MainMenu"
RenderMode
=
"Auto"
EnableRoundedCorners
=
"True"
Width
=
"100%"
OnClientItemClicking
=
"onMainMenuItemClicking"
meta:resourcekey
=
"RadMenu4Resource1"
Style
=
"z-index: 1"
>
<
Items
>
<
telerik:RadMenuItem
runat
=
"server"
Text
=
"Create New"
NavigateUrl
=
"#CreateDocumentManagerAccount"
meta:resourcekey
=
"CreateDocumentManagerAccount"
>
</
telerik:RadMenuItem
>
<!-- when i click in "Create New" button a AjaxManager_request occours and i lost my grid information -->
<
telerik:RadMenuItem
runat
=
"server"
Text
=
"Delete"
NavigateUrl
=
"#DeleteDocumentManagerAccount"
meta:resourcekey
=
"DeleteDocumentManagerAccount"
>
</
telerik:RadMenuItem
>
</
Items
>
</
telerik:RadMenu
>
<
telerik:RadTabStrip
ID
=
"TabForecastList"
runat
=
"server"
MultiPageID
=
"ForecastPagesViews"
Orientation
=
"HorizontalTop"
OnClientLoad
=
"OnClientLoad"
SelectedIndex
=
"0"
>
</
telerik:RadTabStrip
>
<
telerik:RadMultiPage
ID
=
"ForecastPagesViews"
runat
=
"server"
OnPageViewCreated
=
"ForecastPagesViews_PageViewCreated"
Orientation
=
"HorizontalTop"
SelectedIndex
=
"0"
PerTabScrolling
=
"true"
RenderMode
=
"Classic"
ReorderTabsOnSelect
=
"true"
>
<
telerik:RadPageView
ID
=
"DocumentClientsPageView"
runat
=
"server"
Height
=
"600px"
>
<
telerik:RadGrid
runat
=
"server"
ID
=
"ForecastClientesRadGrid"
AutoGenerateColumns
=
"False"
Height
=
"600px"
BorderWidth
=
"0px"
AllowSorting
=
"True"
Style
=
"outline: none"
EnableLinqExpressions
=
"False"
OnItemCommand
=
"ForecastClientesRadGrid_ItemCommand"
ShowGroupPanel
=
"True"
FilterMenu-Enabled
=
"true"
OnDetailTableDataBind
=
"ForecastClientesRadGrid_DetailTableDataBind"
OnNeedDataSource
=
"ForecastClientesRadGrid_NeedDataSource"
AllowPaging
=
"True"
FilterType
=
"Combined"
AllowFilteringByColumn
=
"True"
AllowMultiRowEdit
=
"True"
AllowAutomaticUpdates
=
"True"
>
<
ClientSettings
Scrolling-AllowScroll
=
"True"
Scrolling-UseStaticHeaders
=
"true"
Selecting-AllowRowSelect
=
"true"
AllowGroupExpandCollapse
=
"True"
AllowDragToGroup
=
"true"
EnableRowHoverStyle
=
"true"
>
<
Selecting
AllowRowSelect
=
"True"
/>
<
Scrolling
AllowScroll
=
"True"
UseStaticHeaders
=
"True"
/>
<
ClientEvents
OnRowDblClick
=
"OnRowDblClick"
/>
</
ClientSettings
>
<
PagerStyle
Mode
=
"NumericPages"
PageSizeControlType
=
"None"
></
PagerStyle
>
<
MasterTableView
TableLayout
=
"Fixed"
PageSize
=
"16"
Width
=
"100%"
ClientDataKeyNames
=
"ID"
DataKeyNames
=
"Id"
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"Id"
Name
=
"Forecast"
Width
=
"100%"
AllowFilteringByColumn
=
"false"
>
<
Columns
>
<
telerik:GridButtonColumn
CommandName
=
"RowClick"
ImageUrl
=
"../Images/edit.png"
ButtonType
=
"ImageButton"
ItemStyle-HorizontalAlign
=
"Center"
ItemStyle-Width
=
"30px"
HeaderStyle-Width
=
"30px"
UniqueName
=
"imageSingleClick"
>
</
telerik:GridButtonColumn
>
<
telerik:GridBoundColumn
DataField
=
"Id"
DataType
=
"System.Int32"
HeaderText
=
"Id"
SortExpression
=
"Id"
UniqueName
=
"Id"
Display
=
"false"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
/>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Description"
HeaderText
=
"Description"
SortExpression
=
"Description"
AllowFiltering
=
"false"
UniqueName
=
"Description"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
/>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"Id"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter Id column"
HeaderText
=
"Id"
SortExpression
=
"Id"
UniqueName
=
"Id"
Display
=
"false"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
/>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Name"
FilterControlAltText
=
"Filter NIF column"
HeaderText
=
"Name"
SortExpression
=
"Name"
UniqueName
=
"Name"
HeaderButtonType
=
"TextButton"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
/>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
PagerStyle
PageSizeControlType
=
"None"
/>
</
MasterTableView
>
<
FilterMenu
CssClass
=
"RadFilterMenu_CheckList"
>
</
FilterMenu
>
</
telerik:RadGrid
>
</
telerik:RadPageView
>
</
telerik:RadMultiPage
>
<
telerik:RadScriptBlock
runat
=
"server"
>
<
script
type
=
"text/javascript"
src
=
"../Scripts/pages/forecastManagerAccount.js"
></
script
>
<
script
type
=
"text/javascript"
src
=
"../Scripts/lib/tabLib.js"
></
script
>
<
script
type
=
"text/javascript"
>
//
<![CDATA[
$(document).ready(function () {
window.forecastManager = new Object();
window.forecastManager.ajaxManager = $find("<%= ForecastAjaxManager.ClientID %>");
});
function OnRowDblClick(sender, args) {
var index = args._itemIndexHierarchical;
__doPostBack("<%= ForecastClientesRadGrid.UniqueID %>", "<%= this.CustomDoubleClickCommand %>" + ":" + index);
}
function onMainMenuItemClicking(sender, args) {
mainMenuItemClicking(sender, args);
}
//]]>
</
script
>
</
telerik:RadScriptBlock
>
<
common:notification
runat
=
"server"
ID
=
"NotificationDialog"
/>
</
asp:Content
>
And respective code-behind
using
LCG.Business.Entities.Contacts;
using
LCG.Client.Contracts.Service;
using
LCG.Client.Proxies.Proxies;
using
LCG.Web.IAMS.AWA.Code;
using
LCG.Web.IAMS.AWA.Controls.Documents;
using
LCG.Web.IAMS.AWA.Controls.Forecast;
using
System;
using
System.Collections;
using
System.Collections.Generic;
using
System.Globalization;
using
System.Linq;
using
System.Threading;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
namespace
LCG.Web.IAMS.AWA.Pages
{
public
partial
class
ForeCastManager : System.Web.UI.Page
{
ServiceFactory factory =
new
ServiceFactory();
private
SessionClientCredentials _credentials;
private
SessionClientCredentials credentials
{
get
{
if
(_credentials ==
null
)
_credentials = SessionCredentials.GetCurrentUser();
return
_credentials;
}
}
public
static
string
PageUrl = System.Web.VirtualPathUtility.ToAbsolute(
"~/Pages/ForeCastManager.aspx"
);
private
static
string
_moduleName =
"Forecast"
;
public
string
CustomDoubleClickCommand
{
get
{
return
"CustomRowDoubleClick"
;
}
}
public
int
TabIndex
{
get
{
return
(
int
?)Session[
"tabIndex"
] ?? TabForecastList.Tabs.Count;
}
set
{
Session[
"tabIndex"
] = value;
}
}
#region Page events
protected
void
Page_Init(
object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
{
TabForecastList.Tabs.Add(
new
RadTab() { Text = _moduleName });
TabIndex = 1;
}
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
ForecastAjaxManager.AjaxRequest += ForecastAjaxManager_AjaxRequest;
var tabTemplate =
new
TabTemplate();
foreach
(RadTab tab
in
TabForecastList.Tabs)
{
if
(!tab.Text.Equals(_moduleName, StringComparison.InvariantCultureIgnoreCase))
{
tabTemplate.InstantiateIn(tab, _moduleName);
}
}
if
(!IsPostBack)
{
//TODO:Alterar isto para resources
Page.Title =
"IAMS - Forecast"
;
RadSkinManager skinManager =
new
RadSkinManager();
if
(HttpContext.Current.Session[
"cultureId"
] !=
null
)
{
string
cultureId = (
string
)HttpContext.Current.Session[
"cultureId"
];
Thread.CurrentThread.CurrentUICulture =
new
CultureInfo(cultureId);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureId);
}
}
}
private
void
AddTab(
string
title,
string
id)
{
var tabTemplate =
new
TabTemplate();
RadTab tab =
new
RadTab() { Text = title };
tab.PostBack =
false
;
tabTemplate.InstantiateIn(tab, _moduleName);
TabForecastList.Tabs.Insert(TabForecastList.Tabs.Count, tab);
TabForecastList.DataBind();
TabForecastList.SelectedIndex = tab.Index;
}
private
void
AddPageView(
bool
isNew,
string
pvId)
{
try
{
RadPageView pageView =
new
RadPageView();
if
(isNew)
{
pageView.ID =
"NewForecast"
+ pvId;
//TabIndex++;
}
else
{
pageView.ID = pvId;
}
pageView.CssClass =
"pageView"
;
ForecastPagesViews.PageViews.Add(pageView);
ForecastPagesViews.SelectedIndex = pageView.Index;
}
catch
(Exception ex)
{
throw
ex;
}
}
private
void
ForecastAjaxManager_AjaxRequest(
object
sender, AjaxRequestEventArgs e)
{
string
argument = e.Argument.ToLower();
string
[] strCommand = argument.Split(
'|'
);
if
(strCommand !=
null
)
{
switch
(strCommand[0])
{
case
"createdocumentmanageraccount"
:
TabIndex++;
AddTab(
"NewForecast"
, TabIndex.ToString());
AddPageView(
true
, TabIndex.ToString());
break
;
case
"savedocument"
:
ForecastInfo forecastInfo = FindFileTreeInfoControl(ForecastPagesViews.SelectedPageView.ID);
if
(forecastInfo ==
null
)
{
forecastInfo = FindFileTreeInfoControl(
string
.Format(
"NewForecast{0}"
, TabIndex));
}
forecastInfo.Save();
break
;
default
:
break
;
}
}
}
private
ForecastInfo FindFileTreeInfoControl(
string
id)
{
Control foundControl = ForecastPagesViews.SelectedPageView.FindControl(id);
if
(foundControl ==
null
|| foundControl.Controls ==
null
|| foundControl.Controls.Count == 0)
{
NotificationDialog.Show(
"Error"
,
"An error occured getting the document."
, TypeOfNotifications.Warning);
}
return
(ForecastInfo)foundControl.Controls[0];
}
#endregion
protected
void
ForecastPagesViews_PageViewCreated(
object
sender, Telerik.Web.UI.RadMultiPageEventArgs e)
{
if
(e.PageView.ID.Contains(
"NewForecast"
))
{
e.PageView.Controls.Add(LoadDocumentInfo(0));
}
else
{
e.PageView.Controls.Add(LoadDocumentInfo(
int
.Parse(e.PageView.ID)));
}
}
private
Control LoadDocumentInfo(
int
forecastId)
{
ForecastInfo forecastInfo = (ForecastInfo)Page.LoadControl(
"~/Controls/Forecast/ForecastInfo.ascx"
);
var proxyCompany = factory.CreateClient<IContactService>(credentials,
false
);
forecastInfo.SaveForecast += ForecastInfo_SaveForecast;
if
(forecastId == 0)
{
forecastInfo.Forecast =
new
Forecast();
forecastInfo.ID =
string
.Format(
"ForecastInfonewForecast{0}"
, TabIndex);
}
else
{
Forecast forecast =
new
Forecast();
forecast.Id = forecastId;
forecast = proxyCompany.GetForecastById(forecast);
#region EDIT
proxyCompany.OpenChannel();
forecastInfo.Forecast = forecast;
//TODO: alterar isto
forecastInfo.Companies = proxyCompany.GetCompanies(credentials.Account, credentials.User, 100,
""
).ToList();
forecastInfo.Description = forecast.Description;
forecastInfo.LoadForeCast();
proxyCompany.CloseChannel();
#endregion
}
return
forecastInfo;
}
private
void
ForecastInfo_SaveForecast(Forecast forecast, EventArgs e)
{
var proxy = factory.CreateClient<IContactService>(credentials,
false
);
try
{
proxy.OpenChannel();
Forecast newForecast = proxy.GetForecastById(forecast);
if
(newForecast ==
null
)
{
newForecast =
new
Forecast();
}
newForecast.Description = forecast.Description;
newForecast.CompanyId = forecast.CompanyId;
newForecast.Id = forecast.Id;
newForecast.Records = forecast.Records;
if
(forecast.Id != 0)
{
proxy.UpdateForecast(forecast);
}
else
{
proxy.CreateForecast(forecast);
}
TabForecastList.SelectedTab.Text = newForecast.Description;
Label lbl = (Label)TabForecastList.SelectedTab.FindControl(
"lblTabTitle"
);
lbl.Text = newForecast.Description;
ForecastClientesRadGrid.DataBind();
}
catch
(Exception ex)
{
throw
ex;
}
finally
{
proxy.CloseChannel();
}
}
protected
void
ForecastClientesRadGrid_ItemCommand(
object
sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if
(e.CommandName ==
"RowClick"
)
{
GridEditableItem editedItem = e.Item
as
GridEditableItem;
Hashtable newValues =
new
Hashtable();
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
int
entityId = newValues[
"Id"
] !=
null
? Convert.ToInt32(newValues[
"Id"
]) : 0;
string
title = newValues[
"Description"
].ToString().Length > 20 ?
string
.Format(
"{0}..."
, newValues[
"Description"
].ToString().Substring(0, 20)) : newValues[
"Description"
].ToString();
string
eventArgument =
string
.Format(
"{0}:{1}:{2}"
, e.CommandName, entityId, title);
OpenTab(eventArgument);
}
}
protected
void
ForecastClientesRadGrid_DetailTableDataBind(
object
sender, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
{
GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
var proxyForecast = factory.CreateClient<IContactService>(credentials);
switch
(e.DetailTableView.Name)
{
//1º
case
"Forecast"
:
{
string
CompanyId = dataItem.GetDataKeyValue(
"Id"
).ToString();
e.DetailTableView.DataSource = proxyForecast.GetForeCastsByCompany(CompanyId).ToList();
break
;
}
}
}
protected
void
ForecastClientesRadGrid_NeedDataSource(
object
sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
if
(!e.IsFromDetailTable)
{
var proxy = factory.CreateClient<IContactService>(credentials);
List<Company> lstCompanies =
new
List<Company>();
lstCompanies.AddRange(proxy.GetAllCompanies(credentials.Account, credentials.User).ToList());
ForecastClientesRadGrid.DataSource = lstCompanies;
}
}
private
void
OpenTab(
string
eventArgument)
{
string
[] command = eventArgument.Split(
':'
);
string
taskId =
string
.Empty;
string
title =
string
.Empty;
switch
(command[0])
{
case
"CustomRowDoubleClick"
:
GridDataItem dataItem = (GridDataItem)ForecastClientesRadGrid.SelectedItems[0];
if
(command.Length == 6 || (command.Length == 3 && dataItem[
"AbbreviatedName"
].Text.Contains(
"DM#"
)))
{
taskId = dataItem[
"Id"
].Text;
title = dataItem[
"Description"
].Text;
title = (title.Length > 20 ? title.Substring(0, 20) +
"..."
: title);
}
break
;
case
"RowClick"
:
taskId = command[1];
title = command[2];
break
;
default
:
break
;
}
if
(!
string
.IsNullOrEmpty(taskId))
{
if
(TabForecastList.FindTabByText(title) ==
null
)
{
AddTab(title, taskId);
AddPageView(
false
, taskId);
}
else
{
TabForecastList.FindTabByText(title).Selected =
true
;
ForecastPagesViews.PageViews[TabForecastList.FindTabByText(title).Index].Selected =
true
;
}
}
}
}
}
Someone can help me?
Best regards,