Example E65
Visible to All Users

Grid View for ASP.NET Web Forms - How to edit row data in a new window

This example demonstrates how to edit a record in a new window (in a separate aspx page).

Files to Review

Example Code

WebSite/Default.aspx
ASPx
<%@ Register Assembly="DevExpress.Web.v14.1, Version=14.1.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %> <%-- BeginRegion Page setup --%> <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Grid_Editing_CustomUpdate_CustomUpdate" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <%-- EndRegion --%> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Editing in a new window</title> </head> <body> <form id="form1" runat="server"> <dx:ASPxGridView ID="gridServer" ClientInstanceName="gridClient" runat="server" DataSourceID="ObjectDataSource1" KeyFieldName="Id" Width="300px"> <%-- BeginRegion Grid Columns --%> <Columns> <dx:GridViewDataColumn VisibleIndex="0"> <DataItemTemplate> <a onclick="window.open('EditForm.aspx?<%# Eval("Id") %>', '', 'dependent=yes,width=300,height=320');" href="javascript:void(0);">Edit</a> </DataItemTemplate> </dx:GridViewDataColumn> <dx:GridViewDataColumn FieldName="Id" VisibleIndex="1"> </dx:GridViewDataColumn> <dx:GridViewDataColumn FieldName="Name" VisibleIndex="2"> </dx:GridViewDataColumn> <dx:GridViewDataColumn FieldName="Quantity" VisibleIndex="3"> </dx:GridViewDataColumn> <dx:GridViewDataTextColumn FieldName="Price" VisibleIndex="4"> <PropertiesTextEdit DisplayFormatString="c"> </PropertiesTextEdit> </dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn FieldName="Total" VisibleIndex="5"> <PropertiesTextEdit DisplayFormatString="c"> </PropertiesTextEdit> </dx:GridViewDataTextColumn> </Columns> <%-- EndRegion --%> <SettingsEditing EditFormColumnCount="2" /> </dx:ASPxGridView> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetItems" UpdateMethod="Update" DeleteMethod="Delete" InsertMethod="Insert" TypeName="InvoiceItemsProvider"> </asp:ObjectDataSource> </form> </body> </html>
WebSite/EditForm.aspx
ASPx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EditForm.aspx.cs" Inherits="Grid_Editing_EditInSecondForm_EditForm" %> <!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>Edit a record:</title> <script type="text/javascript"> function CloseScript() { if (window.opener != null) { window.opener.focus(); window.opener.gridClient.Refresh(); } window.close(); } </script> </head> <body> <form id="form1" runat="server"> <div> <table border="0"> <tr> <td>Name: </td><td><asp:TextBox runat="server" ID="tbName" /></td> </tr> <tr> <td>Quantity: </td><td><asp:TextBox runat="server" ID="tbQuantity" /></td> </tr> <tr> <td>Price:</td> <td><asp:TextBox runat="server" ID="tbPrice" /></td> </tr> <tr> <td></td> <td style="text-align:right"> <asp:LinkButton runat="server" ID="btnUpdate" Text="Update" OnClick="btnUpdate_Click"></asp:LinkButton> <a href="javascript:window.close();">Cancel</a> </td> </tr> </table> </div> </form> </body> </html>
WebSite/EditForm.aspx.cs(vb)
C#
using System; public partial class Grid_Editing_EditInSecondForm_EditForm: System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { LoadInitialData(); } } protected void btnUpdate_Click(object sender, EventArgs e) { SaveData(); //ClientScript.RegisterStartupScript(this.GetType(), "closescript", "<script language='javascript'>window.opener.focus(); window.close();</script>"); ClientScript.RegisterStartupScript(this.GetType(), "CloseScriptKey", "CloseScript();</script>", true); } InvoiceItem GetItemId() { int id; if (int.TryParse(Request.Params[0], out id)) { return (new InvoiceItemsProvider()).GetItemById(id); } return null; } void LoadInitialData() { InvoiceItem item = GetItemId(); if (item != null) { tbName.Text = item.Name; tbPrice.Text = item.Price.ToString(); tbQuantity.Text = item.Quantity.ToString(); } } void SaveData() { InvoiceItem item = GetItemId(); if (item != null) { item.Name = tbName.Text; decimal price; if (decimal.TryParse(tbPrice.Text, out price)) { item.Price = price; } int quantity; if (int.TryParse(tbQuantity.Text, out quantity)) { item.Quantity = quantity; } } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.