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.
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.
Razorsettings.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(); }); });
JavaScriptfunction ShowDetailPopup(url) {
popup.SetContentUrl(url);
popup.Show()
}
Files to Review
Documentation
More Examples
Example Code
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));
}
}
}
JavaScriptfunction ShowDetailPopup(url) {
popup.SetContentUrl(url);
popup.Show()
}
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()