I have a Radgrid on ASP.NET Form (RadControls for ASP.NET AJAX Q2 2012 SP2 with VS 2010) , which is bound to a Linq data source and set it to have 10 records per page , sorting, filtering is enabled. Also have a hyper a link column (Radgrid Mastertable Databound column) on the Radgrid, such that a user can click it & navigate to another external page (details.aspx) from the list. I am passing Master Table Primary Key that is Parent key of all rows in Detail Page. On the details page, they have "Back" button to return to the RadGrid page.
I am looking for sample code snippet on the Server/Client Side on how to specify the page/row index to set the RadGrid after data binding. The idea is to ensure the user navigates to the same Radgrid (Parent) page/row index they were originally on after exiting from details.aspx.
Thanks
gc_0620
14 Answers, 1 is accepted

protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
int
CurrentPageIndex = 0;
if
(Session[
"CurrentPageIndex"
] !=
null
)
{
int
.TryParse(Convert.ToString(Session[
"CurrentPageIndex"
]),
out
CurrentPageIndex);
}
RadGrid1.CurrentPageIndex = CurrentPageIndex ;
}
}
protected
void
RadGrid1_ItemCommand(
object
sender, GridCommandEventArgs e)
{
Session[
"CurrentPageIndex"
] = RadGrid1.CurrentPageIndex;
// OR
if
(e.CommandName.ToString().ToLower().IndexOf(
"page"
) >= 0)
{
Session[
"CurrentPageIndex"
] = RadGrid1.CurrentPageIndex;
}
}
Thanks,
Jayesh Goyani

Sorry Jayesh,
It did not work. Basically I have 2 pages, Default.aspx and Default2.aspx. Each of the page has 2 Link buttons (LinkButtonDefault and LinkButtonDefault2) on top of Grid to Navigate between pages. Assuming if I am in Page 6 of Default.aspx and clicked Link button LinkButtonDefault to Navigate to Default2.aspx.
My intention is upon Navigate back from Default2.aspx (via its Link Button) to Default.aspx, Page 6 of Default.aspx will be the current page Index. But unfortunately its opening the 1st Page of Default.aspx.
gc_0620
_____________
Below is my Declaration of each Page:
Default.Aspx;
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!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
id
=
"Head1"
runat
=
"server"
>
<
title
>Default.aspx </
title
>
</
head
>
<
body
class
=
"BODY"
>
<
form
runat
=
"server"
id
=
"mainForm"
method
=
"post"
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
/>
<!-- content start -->
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGrid1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
asp:LinkButton
ID
=
"LinkButtonDefault"
CausesValidation
=
"false"
OnClick
=
"GotoDefault2_Click"
runat
=
"server"
>Go to Default2</
asp:LinkButton
>
<
br
/>
<
br
/>
<
telerik:RadGrid
ID
=
"RadGrid1"
DataSourceID
=
"SqlDataSource1"
runat
=
"server"
ShowStatusBar
=
"True"
AutoGenerateColumns
=
"False"
AllowSorting
=
"True"
AllowPaging
=
"True"
PageSize
=
"10"
GridLines
=
"None"
AllowAutomaticDeletes
=
"True"
AllowAutomaticInserts
=
"True"
AllowAutomaticUpdates
=
"True"
OnItemUpdated
=
"RadGrid1_ItemUpdated"
OnItemDeleted
=
"RadGrid1_ItemDeleted"
OnItemInserted
=
"RadGrid1_ItemInserted"
OnInsertCommand
=
"RadGrid1_InsertCommand"
OnItemCreated
=
"RadGrid1_ItemCreated"
AllowFilteringByColumn
=
"True"
CellSpacing
=
"0"
Skin
=
"Office2010Silver"
OnItemCommand
=
"RadGrid1_ItemCommand"
>
<
PagerStyle
Mode
=
"NumericPages"
></
PagerStyle
>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"True"
/>
</
ClientSettings
>
<
MasterTableView
DataSourceID
=
"SqlDataSource1"
DataKeyNames
=
"CustomerID"
AllowMultiColumnSorting
=
"True"
Width
=
"100%"
CommandItemDisplay
=
"Top"
Name
=
"Customers"
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
></
CommandItemSettings
>
<
RowIndicatorColumn
Visible
=
"True"
FilterControlAltText
=
"Filter RowIndicator column"
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
Visible
=
"True"
FilterControlAltText
=
"Filter ExpandColumn column"
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
UniqueName
=
"EditCommandColumn"
>
<
HeaderStyle
Width
=
"20px"
/>
<
ItemStyle
CssClass
=
"MyImageButton"
/>
</
telerik:GridEditCommandColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"CustomerID"
HeaderText
=
"CustomerID"
HeaderButtonType
=
"TextButton"
DataField
=
"CustomerID"
UniqueName
=
"CustomerID"
MaxLength
=
"5"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"ContactName"
HeaderText
=
"Contact Name"
HeaderButtonType
=
"TextButton"
DataField
=
"ContactName"
UniqueName
=
"ContactName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"CompanyName"
HeaderText
=
"Company"
HeaderButtonType
=
"TextButton"
DataField
=
"CompanyName"
UniqueName
=
"CompanyName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"Address"
HeaderText
=
"Address"
HeaderButtonType
=
"TextButton"
DataField
=
"Address"
UniqueName
=
"Address"
>
</
telerik:GridBoundColumn
>
<
telerik:GridButtonColumn
ConfirmText
=
"Delete this customer?"
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
>
<
HeaderStyle
Width
=
"20px"
/>
<
ItemStyle
HorizontalAlign
=
"Center"
CssClass
=
"MyImageButton"
/>
</
telerik:GridButtonColumn
>
</
Columns
>
<
SortExpressions
>
<
telerik:GridSortExpression
FieldName
=
"CompanyName"
></
telerik:GridSortExpression
>
</
SortExpressions
>
<
EditFormSettings
>
<
EditColumn
UniqueName
=
"EditCommandColumn1"
FilterControlAltText
=
"Filter EditCommandColumn1 column"
>
</
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
FilterMenu
EnableImageSprites
=
"False"
>
</
FilterMenu
>
</
telerik:RadGrid
>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
DeleteCommand="DELETE FROM [Customers] WHERE [CustomerID] = @CustomerID" InsertCommand="INSERT INTO [Customers] ([CustomerID], [CompanyName], [ContactName], [Address]) VALUES (@CustomerID, @CompanyName, @ContactName, @Address)"
SelectCommand="SELECT * FROM [Customers]" UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName, [ContactName] = @ContactName, [Address] = @Address WHERE [CustomerID] = @CustomerID">
<
DeleteParameters
>
<
asp:Parameter
Name
=
"CustomerID"
Type
=
"String"
/>
</
DeleteParameters
>
<
InsertParameters
>
<
asp:Parameter
Name
=
"CustomerID"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"CompanyName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"ContactName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Address"
Type
=
"String"
/>
</
InsertParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"CompanyName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"ContactName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Address"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"CustomerID"
Type
=
"String"
/>
</
UpdateParameters
>
</
asp:SqlDataSource
>
<
br
/>
<!-- content end -->
</
form
>
</
body
>
</
html
>
________________
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using Telerik.Web.UI;
public partial class _Default : System.Web.UI.Page
{
private void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int CurrentPageIndex = 0;
if (Session["CurrentPageIndex"] != null)
{
int.TryParse(Convert.ToString(Session["CurrentPageIndex"]), out CurrentPageIndex);
}
RadGrid1.CurrentPageIndex = CurrentPageIndex;
}
}
protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)
{
string item = getItemName(e.Item.OwnerTableView.Name);
string field = getFieldName(e.Item.OwnerTableView.Name);
if (e.Exception != null)
{
e.KeepInEditMode = true;
e.ExceptionHandled = true;
DisplayMessage(item + " " + e.Item[field].Text + " cannot be updated. Reason: " + e.Exception.Message);
}
else
{
DisplayMessage(item + " " + e.Item[field].Text + " updated");
}
}
protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e)
{
string item = getItemName(e.Item.OwnerTableView.Name);
if (e.Exception != null)
{
e.ExceptionHandled = true;
DisplayMessage(item + " cannot be inserted. Reason: " + e.Exception.Message);
}
else
{
DisplayMessage(item + " inserted");
}
}
protected void RadGrid1_ItemDeleted(object source, GridDeletedEventArgs e)
{
string item = getItemName(e.Item.OwnerTableView.Name);
string field = getFieldName(e.Item.OwnerTableView.Name);
if (e.Exception != null)
{
e.ExceptionHandled = true;
DisplayMessage(item + " " + e.Item[field].Text + " cannot be deleted. Reason: " + e.Exception.Message);
}
else
{
DisplayMessage(item + " " + e.Item[field].Text + " deleted");
}
}
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
{
}
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
GridEditableItem item = e.Item as GridEditableItem;
if (item != null && item.IsInEditMode && item.ItemIndex != -1)
{
if (item.OwnerTableView.Name == ((RadGrid)sender).MasterTableView.Name)
{
(item.EditManager.GetColumnEditor("CustomerID").ContainerControl.Controls[0] as TextBox).Enabled = false;
}
}
}
private String getItemName(string tableName)
{
switch (tableName)
{
case ("Customers"):
{
return "Customer";
}
case ("Orders"):
{
return "Order";
}
default:
return "";
}
}
private String getFieldName(string tableName)
{
switch (tableName)
{
case ("Customers"):
{
return "CustomerID";
}
case ("Orders"):
{
return "OrderID";
}
default:
return "";
}
}
private void DisplayMessage(string text)
{
RadGrid1.Controls.Add(new LiteralControl(string.Format("<
span
style
=
'color:red'
>{0}</
span
>", text)));
}
protected void GotoDefault2_Click(object sender, EventArgs e)
{
Response.Redirect("Default2.aspx");
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
Session["CurrentPageIndex"] = RadGrid1.CurrentPageIndex;
}
}
Default2.Aspx;
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!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
>Default2.aspx </
title
>
<
style
type
=
"text/css"
>
.MyImageButton
{
cursor: hand;
}
.EditFormHeader td
{
font-size: 14px;
padding: 4px !important;
color: #0066cc;
}
</
style
>
</
head
>
<
body
class
=
"BODY"
>
<
form
runat
=
"server"
id
=
"mainForm"
method
=
"post"
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
/>
<!-- content start -->
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGrid1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
asp:LinkButton
ID
=
"LinkButtonDefault2"
OnClick
=
"GotoDefault2_Click"
runat
=
"server"
>Go to Default Page</
asp:LinkButton
>
<
br
/>
<
br
/>
<
telerik:RadGrid
ID
=
"RadGrid1"
DataSourceID
=
"SqlDataSource1"
runat
=
"server"
ShowStatusBar
=
"true"
AutoGenerateColumns
=
"False"
AllowSorting
=
"True"
AllowMultiRowSelection
=
"False"
PageSize
=
"10"
AllowPaging
=
"True"
GridLines
=
"None"
AllowAutomaticDeletes
=
"True"
AllowAutomaticInserts
=
"True"
AllowAutomaticUpdates
=
"True"
OnItemUpdated
=
"RadGrid1_ItemUpdated"
OnItemDeleted
=
"RadGrid1_ItemDeleted"
OnItemInserted
=
"RadGrid1_ItemInserted"
OnInsertCommand
=
"RadGrid1_InsertCommand"
OnItemCreated
=
"RadGrid1_ItemCreated"
>
<
PagerStyle
Mode
=
"NumericPages"
></
PagerStyle
>
<
MasterTableView
DataSourceID
=
"SqlDataSource1"
DataKeyNames
=
"CustomerID"
AllowMultiColumnSorting
=
"True"
Width
=
"100%"
CommandItemDisplay
=
"Top"
Name
=
"Customers"
>
<
Columns
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
UniqueName
=
"EditCommandColumn"
>
<
HeaderStyle
Width
=
"20px"
/>
<
ItemStyle
CssClass
=
"MyImageButton"
/>
</
telerik:GridEditCommandColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"CustomerID"
HeaderText
=
"CustomerID"
HeaderButtonType
=
"TextButton"
DataField
=
"CustomerID"
UniqueName
=
"CustomerID"
MaxLength
=
"5"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"ContactName"
HeaderText
=
"Contact Name"
HeaderButtonType
=
"TextButton"
DataField
=
"ContactName"
UniqueName
=
"ContactName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"CompanyName"
HeaderText
=
"Company"
HeaderButtonType
=
"TextButton"
DataField
=
"CompanyName"
UniqueName
=
"CompanyName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"Address"
HeaderText
=
"Address"
HeaderButtonType
=
"TextButton"
DataField
=
"Address"
UniqueName
=
"Address"
>
</
telerik:GridBoundColumn
>
<
telerik:GridButtonColumn
ConfirmText
=
"Delete this customer?"
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
>
<
HeaderStyle
Width
=
"20px"
/>
<
ItemStyle
HorizontalAlign
=
"Center"
CssClass
=
"MyImageButton"
/>
</
telerik:GridButtonColumn
>
</
Columns
>
<
SortExpressions
>
<
telerik:GridSortExpression
FieldName
=
"CompanyName"
></
telerik:GridSortExpression
>
</
SortExpressions
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
DeleteCommand="DELETE FROM [Customers] WHERE [CustomerID] = @CustomerID" InsertCommand="INSERT INTO [Customers] ([CustomerID], [CompanyName], [ContactName], [Address]) VALUES (@CustomerID, @CompanyName, @ContactName, @Address)"
SelectCommand="SELECT * FROM [Customers]" UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName, [ContactName] = @ContactName, [Address] = @Address WHERE [CustomerID] = @CustomerID">
<
DeleteParameters
>
<
asp:Parameter
Name
=
"CustomerID"
Type
=
"String"
/>
</
DeleteParameters
>
<
InsertParameters
>
<
asp:Parameter
Name
=
"CustomerID"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"CompanyName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"ContactName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Address"
Type
=
"String"
/>
</
InsertParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"CompanyName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"ContactName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Address"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"CustomerID"
Type
=
"String"
/>
</
UpdateParameters
>
</
asp:SqlDataSource
>
<
br
/>
<!-- content end -->
</
form
>
</
body
>
</
html
>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using Telerik.Web.UI;
public partial class Default2 : System.Web.UI.Page
{
private void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Setting Selected index prior to binding RadGrid:
//If the index is in detail table, parent items will be expanded
//automatically
RadGrid1.SelectedIndexes.Add(1, 0, 1, 0, 0);
//Index of 1, 0, 1, 0, 0 means:
//1 - item with index 1 in the MasterTabelView
//0 - detail table with index 0
//1 - item with index 1 (the second item) in the first detail table
//0 - 0 the third-level detail table
//0 - the item with index 0 in the third-level table
}
}
protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)
{
string item = getItemName(e.Item.OwnerTableView.Name);
string field = getFieldName(e.Item.OwnerTableView.Name);
if (e.Exception != null)
{
e.KeepInEditMode = true;
e.ExceptionHandled = true;
DisplayMessage(item + " " + e.Item[field].Text + " cannot be updated. Reason: " + e.Exception.Message);
}
else
{
DisplayMessage(item + " " + e.Item[field].Text + " updated");
}
}
protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e)
{
string item = getItemName(e.Item.OwnerTableView.Name);
if (e.Exception != null)
{
e.ExceptionHandled = true;
DisplayMessage(item + " cannot be inserted. Reason: " + e.Exception.Message);
}
else
{
DisplayMessage(item + " inserted");
}
}
protected void RadGrid1_ItemDeleted(object source, GridDeletedEventArgs e)
{
string item = getItemName(e.Item.OwnerTableView.Name);
string field = getFieldName(e.Item.OwnerTableView.Name);
if (e.Exception != null)
{
e.ExceptionHandled = true;
DisplayMessage(item + " " + e.Item[field].Text + " cannot be deleted. Reason: " + e.Exception.Message);
}
else
{
DisplayMessage(item + " " + e.Item[field].Text + " deleted");
}
}
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
{
}
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
GridEditableItem item = e.Item as GridEditableItem;
if (item != null && item.IsInEditMode && item.ItemIndex != -1)
{
if (item.OwnerTableView.Name == ((RadGrid)sender).MasterTableView.Name)
{
(item.EditManager.GetColumnEditor("CustomerID").ContainerControl.Controls[0] as TextBox).Enabled = false;
}
else if (item.OwnerTableView.Name == "Details")
{
(item.EditManager.GetColumnEditor("ProductID").ContainerControl.Controls[0] as TextBox).Enabled = false;
}
}
}
private String getItemName(string tableName)
{
switch (tableName)
{
case ("Customers"):
{
return "Customer";
}
case ("Orders"):
{
return "Order";
}
default:
return "";
}
}
private String getFieldName(string tableName)
{
switch (tableName)
{
case ("Customers"):
{
return "CustomerID";
}
case ("Orders"):
{
return "OrderID";
}
default:
return "";
}
}
private void DisplayMessage(string text)
{
RadGrid1.Controls.Add(new LiteralControl(string.Format("<
span
style
=
'color:red'
>{0}</
span
>", text)));
}
protected void GotoDefault2_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
}

Default.aspx.cs
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
int
CurrentPageIndex = 0;
if
(Session[
"DefaultCurrentPageIndex"
] !=
null
)
{
int
.TryParse(Convert.ToString(Session[
"DefaultCurrentPageIndex"
]),
out
CurrentPageIndex);
}
RadGrid1.CurrentPageIndex = CurrentPageIndex ;
}
}
protected
void
RadGrid1_ItemCommand(
object
sender, GridCommandEventArgs e)
{
}
// Your Page Redirection button Click event
protected
void
Button1_Click(
object
sender, EventArgs e)
{
Session[
"DefaultCurrentPageIndex"
] = RadGrid1.CurrentPageIndex;
Response.Redirect(
"YourPageName"
);
}
Default2.aspx.cs
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
int
CurrentPageIndex = 0;
if
(Session[
"Default2CurrentPageIndex"
] !=
null
)
{
int
.TryParse(Convert.ToString(Session[
"Default2CurrentPageIndex"
]),
out
CurrentPageIndex);
}
RadGrid1.CurrentPageIndex = CurrentPageIndex ;
}
}
protected
void
RadGrid1_ItemCommand(
object
sender, GridCommandEventArgs e)
{
}
// Your Page Redirection button Click event
protected
void
Button1_Click(
object
sender, EventArgs e)
{
Session[
"Default2CurrentPageIndex"
] = RadGrid1.CurrentPageIndex;
Response.Redirect(
"YourPageName"
);
}
Thanks,
Jayesh Goyani

gc_0620

protected void RadGridLOC_ItemDataBound(object sender, GridItemEventArgs e)
{
//some code hre...
if (e.Item is GridDataItem)
{
HyperLink hLink = (HyperLink)item["LinkColumn"].Controls[0];
hLink.NavigateUrl = "~/CreateLOC.aspx?in_loc=" + val1 + "&y_loc=" + val2 + "&type=edit";
// some code here...
}
}
In this case, where would I set the CurrentPageIndex? Thanks for any help.

You can use the same approach Jayesh suggested. You can save the current page index in ItemDataBound event like below.
C#:
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
int
CurrentPageIndex = 0;
if
(Session[
"DefaultCurrentPageIndex"
] !=
null
)
{
int
.TryParse(Convert.ToString(Session[
"DefaultCurrentPageIndex"
]),
out
CurrentPageIndex);
}
RadGrid1.CurrentPageIndex = CurrentPageIndex;
}
}
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
HyperLink hLink = (HyperLink)item[
"LinkColumn"
].Controls[0];
Session[
"DefaultCurrentPageIndex"
] = RadGrid1.CurrentPageIndex;
hLink.NavigateUrl =
"yourpage.aspx"
;
}
}
Thanks,
Princy.

Thanks a lot Princy & Jayesh for helping Sharon with her navigating controls. When I started Rad Controls about 5 yrs ago, Princy & Shinu and later Jayesh helped me a lot. Sincerely appreciate that.
All the best,
gc-0620


I'm trying to go one more step by attempting to make the selected row be what it used to be before the user left the current page. WIth Jayesh and Princy's solution, I get to the previous page fine, now I want the previous row to persist. I tried something on my own using some code provided by Princy for another issue, and I nearly got it to work. Unfortunately, it is causing some undesirble side effect, which I dont know how to fix, although for the experts out there I'm sure it is evident. This issue being when I click on a row, it reverts back to the previous row, and then a second click will work. Thanks.
I set the CurrentRowIndex session variable to the current index.
protected void RadGridDetail_ItemDataBound(object sender, GridItemEventArgs e)
{
Session["CurrentRowIndex"] = Convert.ToInt32(RadGridLOC.SelectedIndexes[0]); //getting current parent row index
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
some code here....
protected void RadGridLOC_PreRender(object sender, EventArgs e)
{
if (Convert.ToInt32(Session["CurrentRowIndex"]) > -1)
{
GridDataItem item = (GridDataItem)RadGridLOC.Items[Convert.ToInt32(Session["CurrentRowIndex"])];
item.Selected = true;
RadGridDetail.Rebind();
Session["CurrentRowIndex"] = -1;
}
Thanks for any help.
You can implement the approach demonstrated in the following topic to preserve selection upon databinding operations:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/Selecting/persisting-selected-rows-client-side
Please note that this approach requires the grid to be ajaxified:
http://www.telerik.com/help/aspnet-ajax/ajax-masterpage.html
To get the selected items through all pages on a single button click, you can implement the approach demonstrated in this code-library:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/647760-get-selected-items-through-all-pages.aspx
I hope this helps.
Greetings,
Eyup
the Telerik team

In RadGrid, when i click on pageIndex 4 first time . it show CurrentpagesIndex 0.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int CurrentPageIndex = 0;
if (Session["EmployerCurrentPageIndex"] != null)
{
int.TryParse(Convert.ToString(Session["EmployerCurrentPageIndex"]), out CurrentPageIndex);
}
EmployerLinkGrid1.CurrentPageIndex = CurrentPageIndex;
BindGrid();
}
}
string strCurrentPageIndex = EmployerLinkGrid1.MasterTableView.CurrentPageIndex.ToString();
protected void EmployerLinkGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
Session["EmployerCurrentPageIndex"] = EmployerLinkGrid1.CurrentPageIndex;
}
I check it many way, when click on PagesIndex 4 , it should not show 0. everytime it show previous value.
When click on pageIndex 4, it show 0
then click on pageIndex 1, it show 3
Its really confusing.
Thanks,
Muhammad Waseem
the Telerik Team

OnPageIndexChanged="EmployerLinkGrid1_PageIndexChanged"
protected void EmployerLinkGrid1_PageIndexChanged(object sender, Telerik.Web.UI.GridPageChangedEventArgs e)
{
string str = e.NewPageIndex.ToString();
}
Thanks,
Muhammad Waseem
the Telerik Team

The GridSettingsPersister class is outdated long ago and no longer supported. Now this requirement can be better achieved using RadGrid in combination with RadPersistenceFramework and using the correct time in the page life cycle to load the saved settings:
https://demos.telerik.com/aspnet-ajax/controls/examples/integration/persisting-grid-settings/defaultcs.aspx?product=grid
https://demos.telerik.com/aspnet-ajax/persistence-framework/examples/custom-storage-provider/defaultcs.aspx
I am also sending 2 RadGrid web sites to demonstrate practical implementations.
Regards,
Eyup
Telerik