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" %>
<
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" %>
<
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");
}
}