ASPxGridView.GetMasterRowFieldValues(String[]) Method
Returns the values within the specified master row cells.
Namespace : DevExpress.Web
Assembly :
DevExpress.Web.v24.2.dll
NuGet Package :
DevExpress.Web
# Declaration
public object GetMasterRowFieldValues (
params string [] fieldNames
)
Public Function GetMasterRowFieldValues(
ParamArray fieldNames As String ()
) As Object
# Parameters
Name
Type
Description
fieldNames
String []
The names of data source fields whose values are returned.
# Returns
Type
Description
Object
An object that contains the specified master row cell values.
A detail row is displayed when its corresponding master row is expanded. Use the detail grid’s GetMasterRowFieldValues method to obtain values within the specified master row cells.
# Example
This example shows how to determine a composite key of a master record.NOTE: Starting from v2009 vol 1, the ASPxGridView supports composite keys out-of-the-box: Support for the composite key is required You can use semicolon-separated values to specify multi-field keys: "column1[;columnx]". For example: "FirstName;LastName;Phone;BirthDate".
<%@ Page Language ="C#" AutoEventWireup ="true" CodeFile ="Default.aspx.cs" Inherits ="_Default" %>
<%@ Register Assembly ="DevExpress.Web.ASPxEditors.v8.1" Namespace ="DevExpress.Web.ASPxEditors" TagPrefix ="dxe" %>
<%@ Register Assembly ="DevExpress.Web.ASPxGridView.v8.1" Namespace ="DevExpress.Web.ASPxGridView" TagPrefix ="dxwgv" %>
<!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 > Untitled Page</title >
</head >
<body >
<form id ="form1" runat ="server" >
<dxwgv:ASPxGridView runat ="server" ID ="grid" EnableRowsCache ="false" KeyFieldName ="__Key"
OnLoad ="grid_Load"
OnCustomUnboundColumnData ="grid_CustomUnboundColumnData" >
<Columns >
<dxwgv:GridViewDataTextColumn FieldName ="FirstName" VisibleIndex ="0" />
<dxwgv:GridViewDataTextColumn FieldName ="LastName" VisibleIndex ="1" />
<dxwgv:GridViewDataTextColumn FieldName ="__Key" Visible ="False" UnboundType ="String" />
</Columns >
<SettingsDetail ShowDetailRow ="True" />
<Templates >
<DetailRow >
<dxwgv:ASPxGridView runat ="server" ID ="detail" EnableRowsCache ="false"
OnDataBinding ="detail_DataBinding" >
<SettingsDetail IsDetailGrid ="true" />
</dxwgv:ASPxGridView >
</DetailRow >
</Templates >
</dxwgv:ASPxGridView >
</form >
</body >
</html >
#region Using
using System ;
using System.Collections ;
using System.Collections.Generic ;
#endregion
class MasterItem {
string m_firstName, m_lastName;
public MasterItem (string first, string last ) {
this .m_firstName = first;
this .m_lastName = last;
}
public string FirstName {
get { return m_firstName; }
set { m_firstName = value ; }
}
public string LastName {
get { return m_lastName; }
set { m_lastName = value ; }
}
}
class DetailItem {
string m_firstNameKey, m_lastNameKey;
int m_orderId;
string m_customerName;
public DetailItem (string firstNameKey, string lastNameKey, int orderId, string customerName ) {
this .m_firstNameKey = firstNameKey;
this .m_lastNameKey = lastNameKey;
this .m_orderId = orderId;
this .m_customerName = customerName;
}
public string FirstNameKey {
get { return m_firstNameKey; }
set { m_firstNameKey = value ; }
}
public string LastNameKey {
get { return m_lastNameKey; }
set { m_lastNameKey = value ; }
}
public int OrderId {
get { return m_orderId; }
set { m_orderId = value ; }
}
public string CustomerName {
get { return m_customerName; }
set { m_customerName = value ; }
}
}
public static class DataProvider {
public static IEnumerable CreateMasterData ( ) {
List<MasterItem> list = new List<MasterItem>();
list.Add(new MasterItem("Nancy" , "Davolio" ));
list.Add(new MasterItem("Andrew" , "Fuller" ));
return list;
}
public static IEnumerable CreateDetailData (string firstName, string lastName ) {
List<DetailItem> list = new List<DetailItem>();
switch (firstName + lastName) {
case "NancyDavolio" :
list.Add(new DetailItem(firstName, lastName, 10258 , "Ernst Handel" ));
list.Add(new DetailItem(firstName, lastName, 10270 , "Wartian Herkku" ));
list.Add(new DetailItem(firstName, lastName, 10275 , "Magazzini Alimentari Riuniti" ));
break ;
case "AndrewFuller" :
list.Add(new DetailItem(firstName, lastName, 10265 , "Blondel père et fils" ));
list.Add(new DetailItem(firstName, lastName, 10277 , "Morgenstern Gesundkost" ));
list.Add(new DetailItem(firstName, lastName, 10280 , "Berglunds snabbköp" ));
break ;
}
return list;
}
}
#region Using
using System ;
using System.Data ;
using System.Configuration ;
using System.Web ;
using System.Web.Security ;
using System.Web.UI ;
using System.Web.UI.WebControls ;
using System.Web.UI.WebControls.WebParts ;
using System.Web.UI.HtmlControls ;
using DevExpress.Web.ASPxGridView;
#endregion
public partial class _Default : System .Web .UI .Page {
protected void grid_Load (object sender, EventArgs e ) {
ASPxGridView grid = (ASPxGridView)sender;
grid.DataSource = DataProvider.CreateMasterData();
grid.DataBind();
}
protected void grid_CustomUnboundColumnData (object sender, ASPxGridViewColumnDataEventArgs e ) {
if (e.Column.FieldName == "__Key" )
e.Value = e.GetListSourceFieldValue("FirstName" ).ToString() + e.GetListSourceFieldValue("LastName" ).ToString();
}
protected void detail_DataBinding (object sender, EventArgs e ) {
ASPxGridView grid = (ASPxGridView)sender;
string firstNameKey = grid.GetMasterRowFieldValues("FirstName" ).ToString();
string lastNameKey = grid.GetMasterRowFieldValues("LastName" ).ToString();
grid.DataSource = DataProvider.CreateDetailData(firstNameKey, lastNameKey);
}
}
#Region "Using"
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports DevExpress.Web.ASPxGridView
#End Region
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub grid_Load(ByVal sender As Object , ByVal e As EventArgs)
Dim grid As ASPxGridView = CType (sender, ASPxGridView)
grid.DataSource = DataProvider.CreateMasterData()
grid.DataBind()
End Sub
Protected Sub grid_CustomUnboundColumnData(ByVal sender As Object , ByVal e As ASPxGridViewColumnDataEventArgs)
If e.Column.FieldName = "__Key" Then
e.Value = e.GetListSourceFieldValue("FirstName" ).ToString() & e.GetListSourceFieldValue("LastName" ).ToString()
End If
End Sub
Protected Sub detail_DataBinding(ByVal sender As Object , ByVal e As EventArgs)
Dim grid As ASPxGridView = CType (sender, ASPxGridView)
Dim firstNameKey As String = grid.GetMasterRowFieldValues("FirstName" ).ToString()
Dim lastNameKey As String = grid.GetMasterRowFieldValues("LastName" ).ToString()
grid.DataSource = DataProvider.CreateDetailData(firstNameKey, lastNameKey)
End Sub
End Class
#Region "Using"
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Collections.Generic
#End Region
Friend Class MasterItem
Private m_firstName, m_lastName As String
Public Sub New (ByVal first As String , ByVal last As String )
Me .m_firstName = first
Me .m_lastName = last
End Sub
Public Property FirstName() As String
Get
Return m_firstName
End Get
Set (ByVal value As String )
m_firstName = value
End Set
End Property
Public Property LastName() As String
Get
Return m_lastName
End Get
Set (ByVal value As String )
m_lastName = value
End Set
End Property
End Class
Friend Class DetailItem
Private m_firstNameKey, m_lastNameKey As String
Private m_orderId As Integer
Private m_customerName As String
Public Sub New (ByVal firstNameKey As String , ByVal lastNameKey As String , ByVal orderId As Integer , ByVal customerName As String )
Me .m_firstNameKey = firstNameKey
Me .m_lastNameKey = lastNameKey
Me .m_orderId = orderId
Me .m_customerName = customerName
End Sub
Public Property FirstNameKey() As String
Get
Return m_firstNameKey
End Get
Set (ByVal value As String )
m_firstNameKey = value
End Set
End Property
Public Property LastNameKey() As String
Get
Return m_lastNameKey
End Get
Set (ByVal value As String )
m_lastNameKey = value
End Set
End Property
Public Property OrderId() As Integer
Get
Return m_orderId
End Get
Set (ByVal value As Integer )
m_orderId = value
End Set
End Property
Public Property CustomerName() As String
Get
Return m_customerName
End Get
Set (ByVal value As String )
m_customerName = value
End Set
End Property
End Class
Public NotInheritable Class DataProvider
Private Sub New ()
End Sub
Public Shared Function CreateMasterData() As IEnumerable
Dim list As List(Of MasterItem) = New List(Of MasterItem)()
list.Add(New MasterItem("Nancy" , "Davolio" ))
list.Add(New MasterItem("Andrew" , "Fuller" ))
Return list
End Function
Public Shared Function CreateDetailData(ByVal firstName As String , ByVal lastName As String ) As IEnumerable
Dim list As List(Of DetailItem) = New List(Of DetailItem)()
Select Case firstName & lastName
Case "NancyDavolio"
list.Add(New DetailItem(firstName, lastName, 10258 , "Ernst Handel" ))
list.Add(New DetailItem(firstName, lastName, 10270 , "Wartian Herkku" ))
list.Add(New DetailItem(firstName, lastName, 10275 , "Magazzini Alimentari Riuniti" ))
Case "AndrewFuller"
list.Add(New DetailItem(firstName, lastName, 10265 , "Blondel pere et fils" ))
list.Add(New DetailItem(firstName, lastName, 10277 , "Morgenstern Gesundkost" ))
list.Add(New DetailItem(firstName, lastName, 10280 , "Berglunds snabbkop" ))
End Select
Return list
End Function
End Class
<%@ Page Language ="vb" AutoEventWireup ="true" CodeFile ="Default.aspx.vb" Inherits ="_Default" %>
<%@ Register Assembly ="DevExpress.Web.ASPxEditors.v8.1" Namespace ="DevExpress.Web.ASPxEditors" TagPrefix ="dxe" %>
<%@ Register Assembly ="DevExpress.Web.ASPxGridView.v8.1" Namespace ="DevExpress.Web.ASPxGridView" TagPrefix ="dxwgv" %>
<!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 > Untitled Page</title >
</head >
<body >
<form id ="form1" runat ="server" >
<dxwgv:ASPxGridView runat ="server" ID ="grid" EnableRowsCache ="false" KeyFieldName ="__Key"
OnLoad ="grid_Load"
OnCustomUnboundColumnData ="grid_CustomUnboundColumnData" >
<Columns >
<dxwgv:GridViewDataTextColumn FieldName ="FirstName" VisibleIndex ="0" />
<dxwgv:GridViewDataTextColumn FieldName ="LastName" VisibleIndex ="1" />
<dxwgv:GridViewDataTextColumn FieldName ="__Key" Visible ="False" UnboundType ="String" />
</Columns >
<SettingsDetail ShowDetailRow ="True" />
<Templates >
<DetailRow >
<dxwgv:ASPxGridView runat ="server" ID ="detail" EnableRowsCache ="false"
OnDataBinding ="detail_DataBinding" >
<SettingsDetail IsDetailGrid ="true" />
</dxwgv:ASPxGridView >
</DetailRow >
</Templates >
</dxwgv:ASPxGridView >
</form >
</body >
</html >
See Also