This example demonstrates how to open a pop-up dialog when a user clicks a hyperlink in the grid's column.
Define master and detail GridView settings in separate PartialView files: MasterViewPartial.cshtml and DetailViewPartial.cshtml.
In the master grid, create a templated column and add a hyperlink to the template. In the hyperlink's Click
event handler, send a callback to the detail grid.
XML// MasterViewPartial.cshtml @Html.DevExpress().GridView(settings => { // ... settings.KeyFieldName = "CustomerID"; settings.Columns.Add(col => { col.FieldName = "CustomerID"; col.SetDataItemTemplateContent(container => { Html.DevExpress().HyperLink(hlSettings => { // ... hlSettings.Properties.ClientSideEvents.Click = string.Format("function(s, e) {{ OnHyperLinkClick('{0}'); }}", (container as GridViewDataItemTemplateContainer).KeyValue.ToString()); hlSettings.Properties.Text = "Show Orders"; }).Render(); }); }); // ... }).Bind(Model).GetHtml()
JavaScriptvar currentCustomerID;
function OnHyperLinkClick(customerID) {
currentCustomerID = customerID;
detailGrid.PerformCallback();
}
Handle the client-side BeginCallback event of the detail grid. In the handler, declare the _customerID
property and set it to the current customer ID value. The grid sends this value to the server to filter the detail grid data.
JavaScriptfunction OnDetailGridBeginCallback(s, e) {
e.customArgs["_customerID"] = currentCustomerID;
}
XML// HomeController.cs public PartialViewResult DetailPartialAction(string _customerID) { return PartialView("DetailViewPartial", OrderRepository.GetOrders(_customerID)); }
Handle the client-side EndCallback event of the detail grid to show the Popup control that contains the detail grid with filtered data.
JavaScriptfunction OnDetailGridEndCallback(s, e) {
if (!popup.IsVisible())
popup.Show();
}
XML// Index.cshtml @Html.DevExpress().PopupControl(settings => { // ... settings.SetContent(() => { Html.RenderPartial("DetailViewPartial", null); }); }).GetHtml()
Files to Look At
Documentation
More Examples
- Grid View for ASP.NET MVC - How to Use ContentUrl to Display Detail Data within a Popup Window
- Grid View for ASP.NET Web Forms - How to Display a Popup Dialog When a User Clicks a Link in a Grid Row
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
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());
}
[HttpPost]
public PartialViewResult DetailPartialAction(string _customerID) {
return PartialView("DetailViewPartial", OrderRepository.GetOrders(_customerID));
}
}
}
JavaScriptvar currentCustomerID;
function OnHyperLinkClick(customerID) {
currentCustomerID = customerID;
detailGrid.PerformCallback();
}
function OnDetailGridBeginCallback(s, e) {
e.customArgs["_customerID"] = currentCustomerID;
}
function OnDetailGridEndCallback(s, e) {
if (!popup.IsVisible())
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(400);
settings.SetContent(() => {
Html.RenderPartial("DetailViewPartial", null);
});
}).GetHtml()