This is a migrated thread and some comments may be shown as answers.

On Edit open a new page

1 Answer 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sbowman
Top achievements
Rank 1
sbowman asked on 08 Nov 2008, 10:42 PM
I have a web form with a radgrid on it and when the user clicks edit, I want them to be redirected to another page with the data from the selected record id filled in. I need help figuring out how pass the record id to the new page and then open the new page in the same window. I already have code in the Page_Load event of the new page that fills in data based on an ID that I have hardcoded for now. Here is my aspx page:

<%

@ Page Language="VB" MasterPageFile="~/Masters/PU89AdminMasterPage.master" AutoEventWireup="false" CodeFile="EditNews.aspx.vb" Inherits="Admin_EditNews" title="PU89 - Admin Area" %>

 

<%

@ Register Assembly="Telerik.Web.UI, Version=2008.2.1001.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4"

 

 

Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

 

<

asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">

 

<

Table id="tblAdminEditNews" runat="server" class="PageFont">

 

 

<tr>

 

 

<td style="height: 10px">&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp</td>

 

 

<td class="HeaderText" style="border-bottom: solid 3px #FF7700; height: 10px" colspan="2">PU89 Admin: News - Edit</td>

 

 

</tr>

 

 

<tr>

 

 

<td style="height: 10px">&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp</td>

 

 

<td style="width: 694px">

 

 

<telerik:RadGrid ID="rgdEditNews" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="dsEditNews"

 

 

GridLines="None" PageSize="30" Width="100%" Skin="Gray" OnDeleteCommand="rgdEditNews_DeleteCommand"

 

 

OnNeedDataSource="rgdEditNews_NeedDataSource" OnEditCommand="rgdEditNews_EditCommand">

 

 

<MasterTableView AutoGenerateColumns="False" DataSourceID="dsEditNews" Width="693px" DataKeyNames="ID">

 

 

<RowIndicatorColumn>

 

 

<HeaderStyle Width="20px" />

 

 

</RowIndicatorColumn>

 

 

<ExpandCollapseColumn>

 

 

<HeaderStyle Width="20px" />

 

 

</ExpandCollapseColumn>

 

 

<Columns>

 

 

<telerik:GridButtonColumn CommandName="Edit" Text="Edit" UniqueName="column1">

 

 

</telerik:GridButtonColumn>

 

 

<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="column1">

 

 

</telerik:GridButtonColumn>

 

 

<telerik:GridBoundColumn DataField="Title" EmptyDataText="&amp;nbsp;" HeaderText="Title"

 

 

SortExpression="Title" UniqueName="Title">

 

 

<ItemStyle Width="425px" />

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="BDate" DataType="System.DateTime" EmptyDataText="&amp;nbsp;"

 

 

HeaderText="Date" SortExpression="BDate" UniqueName="BDate">

 

 

<ItemStyle Width="100px" />

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridCheckBoxColumn DataField="Display" DataType="System.Boolean" HeaderText="Display"

 

 

SortExpression="Display" UniqueName="Display">

 

 

<ItemStyle Width="100px" />

 

 

</telerik:GridCheckBoxColumn>

 

 

<telerik:GridBoundColumn DataField="ID" Display="False" EmptyDataText="&amp;nbsp;"

 

 

UniqueName="ID" Visible="False">

 

 

</telerik:GridBoundColumn>

 

 

</Columns>

 

 

</MasterTableView>

 

 

<ClientSettings>

 

 

<Scrolling AllowScroll="True" UseStaticHeaders="True" />

 

 

</ClientSettings>

 

 

<FilterMenu EnableTheming="True" Skin="Gray">

 

 

<CollapseAnimation Duration="200" Type="OutQuint" />

 

 

</FilterMenu>

 

 

</telerik:RadGrid><asp:SqlDataSource ID="dsEditNews" runat="server" ConnectionString="<%$ ConnectionStrings:PU89 %>"

 

 

SelectCommand="SELECT [ID], [Title], [BDate], [Display] FROM [tblNews]" ConflictDetection="CompareAllValues" DeleteCommand="DELETE FROM [tblNews] WHERE [ID] = @original_ID AND [Title] = @original_Title AND [BDate] = @original_BDate AND [Display] = @original_Display" InsertCommand="INSERT INTO [tblNews] ([Title], [BDate], [Display]) VALUES (@Title, @BDate, @Display)" OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [tblNews] SET [Title] = @Title, [BDate] = @BDate, [Display] = @Display WHERE [ID] = @original_ID AND [Title] = @original_Title AND [BDate] = @original_BDate AND [Display] = @original_Display">

 

 

</asp:SqlDataSource>

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td style="height:275px">&nbsp</td>

 

 

</tr>

 

</

Table>

 

</

asp:Content>

My edit module is called rgdEditNews_EditCommand but it is empty for now because i wasn't sure where to begin. Thanks!

 

1 Answer, 1 is accepted

Sort by
0
sbowman
Top achievements
Rank 1
answered on 08 Nov 2008, 11:09 PM
Nevermind, I figured it out on my own:

Protected

Sub rgdEditNews_EditCommand(ByVal [source] As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs)

 

 

Dim ID As String = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ID").ToString()

 

Response.Redirect(

"EditNewsItem.aspx?ID=" & ID)

 

 

End Sub

 

Vinita
Top achievements
Rank 1
commented on 21 May 2021, 12:44 PM

Can you please help me out with the same issue?
Attila Antal
Telerik team
commented on 26 May 2021, 09:25 AM

Vinita, you can use the same approach shared by sbowman. In the ItemCommand Event of the Grid, you can get the record ID (instructions in Accessing Raw Field Data and Key Values), and use Response.Redirect to redirect the request to the same or another Page. When you do that,  you can either send the ID using QueryString, Session or Cookies.

 

Tags
Grid
Asked by
sbowman
Top achievements
Rank 1
Answers by
sbowman
Top achievements
Rank 1
Share this question
or