Example E20051
Visible to All Users

Grid View for ASP.NET MVC - How to display detail data in a pop-up window

This example demonstrates how to create a column's template, add a hyperlink to that template, and show a pop-up window with detail grid data on a hyperlink click.

Display detail data in a pop-up window

Overview

Call a column's SetDataItemTemplateContent method and add a hyperlink control to the template. Handle the hyperlink's Click event. In the handler, specify the URL to the page with detail data, pass the URL as a parameter to the popup control's SetContentUrl method, and invoke a pop-up window.

Razor
settings.Columns.Add(col => { col.FieldName = "CustomerID"; col.SetDataItemTemplateContent(container => { Html.DevExpress().HyperLink(hlSettings => { hlSettings.Name = string.Format("hl_{0}", (container as GridViewDataItemTemplateContainer).VisibleIndex); hlSettings.NavigateUrl = "javascript:void(0)"; hlSettings.Properties.ClientSideEvents.Click = string.Format("function(s, e) {{ ShowDetailPopup('{0}'); }}", Url.Action("DetailAction", "Home", new { _customerID = (container as GridViewDataItemTemplateContainer).KeyValue.ToString() })); hlSettings.Properties.Text = "Show Orders"; }).Render(); }); });
JavaScript
function ShowDetailPopup(url) { popup.SetContentUrl(url); popup.Show() }

Files to Review

Documentation

More Examples

Example Code

DisplayDetailInPopupWindow/Controllers/HomeController.cs
C#
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using DisplayDetailInPopupWindow.Models; namespace DisplayDetailInPopupWindow.Controllers { public class HomeController : Controller { public ActionResult Index() { return View(); } [HttpPost] public PartialViewResult MasterAction() { return PartialView("MasterViewPartial", CustomerRepository.GetCustomers()); } public ActionResult DetailAction(string _customerID) { ViewData["customerID"] = _customerID; return View("DetailView", ViewData["customerID"]); } [HttpPost] public PartialViewResult DetailPartialAction(string _customerID) { ViewData["customerID"] = _customerID; return PartialView("DetailViewPartial", OrderRepository.GetOrders(_customerID)); } } }
DisplayDetailInPopupWindow/Scripts/JSCustom.js
JavaScript
function ShowDetailPopup(url) { popup.SetContentUrl(url); popup.Show() }
DisplayDetailInPopupWindow/Views/Home/Index.cshtml
Razor
@{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } @Html.Partial("MasterViewPartial", DisplayDetailInPopupWindow.Models.CustomerRepository.GetCustomers()) @Html.DevExpress().PopupControl(settings => { settings.Name = "popup"; settings.Width = System.Web.UI.WebControls.Unit.Pixel(800); settings.Height = System.Web.UI.WebControls.Unit.Pixel(200); }).GetHtml()
DisplayDetailInPopupWindow/Views/Shared/DetailViewPartial.cshtml
Razor
@model System.Data.DataTable @Html.DevExpress().GridView(settings => { settings.Name = "detailGrid"; settings.CallbackRouteValues = new { Controller = "Home", Action = "DetailPartialAction", _customerID = ViewData["customerID"] }; settings.KeyFieldName = "OrderID"; settings.Columns.Add("OrderID"); settings.Columns.Add("CustomerID"); settings.Columns.Add("Freight"); settings.Columns.Add("ShipName"); settings.Columns.Add("ShipAddress"); settings.Columns.Add("ShipCity"); settings.Columns.Add("ShipCountry"); settings.Columns.Add("ShipPostalCode"); settings.Columns.Add("ShippedDate"); }).Bind(Model).GetHtml()
DisplayDetailInPopupWindow/Views/Shared/MasterViewPartial.cshtml
Razor
@model System.Data.DataTable @Html.DevExpress().GridView(settings => { settings.Name = "masterGrid"; settings.CallbackRouteValues = new { Controller = "Home", Action = "MasterAction" }; settings.KeyFieldName = "CustomerID"; settings.Columns.Add(col => { col.FieldName = "CustomerID"; col.SetDataItemTemplateContent(container => { Html.DevExpress().HyperLink(hlSettings => { hlSettings.Name = string.Format("hl_{0}", (container as GridViewDataItemTemplateContainer).VisibleIndex); hlSettings.NavigateUrl = "javascript:void(0)"; hlSettings.Properties.ClientSideEvents.Click = string.Format("function(s, e) {{ ShowDetailPopup('{0}'); }}", Url.Action("DetailAction", "Home", new { _customerID = (container as GridViewDataItemTemplateContainer).KeyValue.ToString() })); hlSettings.Properties.Text = "Show Orders"; }).Render(); }); }); settings.Columns.Add("CompanyName"); settings.Columns.Add("ContactName"); settings.Columns.Add("ContactTitle"); settings.Columns.Add("Address"); settings.Columns.Add("Country"); settings.Columns.Add("City"); }).Bind(Model).GetHtml()

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.