ASPxClientGridView.GetRowKey(visibleIndex) Method
Returns the key value of the specified data row.
Declaration
GetRowKey(
visibleIndex: number
): string
Parameters
Name |
Type |
Description |
visibleIndex |
number |
The row’s visible index.
|
Returns
Type |
Description |
string |
A string representing the specified data row’s key value. If the index passed via the visibleIndex parameter is wrong, or the ASPxGridBase.KeyFieldName property is not set, null is returned.
|
The GetRowKey
method is in effect for data rows only – it does not work for group rows.
Note
If multiple key fields are set via the grid’s ASPxGridBase.KeyFieldName property, a specific service vertical bar symbol (the symbol |) is used to separate key field values in the string returned by the GetRowKey
method.
Online Example
View Example: How to use jQuery to drag and drop items from one grid to another
Example
This example demonstrates how to use the ASPxDataView control to show the ASPxGridView’s detail data.
View Example
using System;
using System.Web.UI;
using DevExpress.Web.ASPxDataView;
public partial class _Default : System.Web.UI.Page {
protected void ASPxDataView1_Load(object sender, EventArgs e) {
if (Session["CategoryID"] == null) return;
AccessDataSource1.SelectParameters["CategoryID"].DefaultValue = Session["CategoryID"].ToString();
(sender as ASPxDataView).DataBind();
}
protected void ASPxDataView1_CustomCallback(object sender, DevExpress.Web.CallbackEventArgsBase e) {
Session["CategoryID"] = e.Parameter;
AccessDataSource1.SelectParameters["CategoryID"].DefaultValue = e.Parameter;
(sender as ASPxDataView).DataBind();
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v10.1, Version=10.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v10.1, Version=10.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxDataView" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v10.1, Version=10.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<!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 id="Head1" runat="server">
<title></title>
<script type="text/javascript" language="javascript">
function FocusedRowChanged(s, e) {
dataview.PerformCallback(s.GetRowKey(s.GetFocusedRowIndex()));
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource2"
KeyFieldName="CategoryID" ClientInstanceName="grid">
<SettingsBehavior AllowFocusedRow="True" />
<ClientSideEvents FocusedRowChanged="FocusedRowChanged" />
<Columns>
<dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="CategoryName" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Description" VisibleIndex="2">
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT [CategoryID], [CategoryName], [Description], [Picture] FROM [Categories]">
</asp:AccessDataSource>
</div>
<dx:ASPxDataView ID="ASPxDataView1" runat="server" ColumnCount="1" DataSourceID="AccessDataSource1"
RowPerPage="1" ClientInstanceName="dataview" OnCustomCallback="ASPxDataView1_CustomCallback"
OnLoad="ASPxDataView1_Load">
<ItemTemplate>
<b>ProductID</b>:
<asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' />
<br />
<b>ProductName</b>:
<asp:Label ID="ProductNameLabel" runat="server" Text='<%# Eval("ProductName") %>' />
<br />
<b>CategoryID</b>:
<asp:Label ID="CategoryIDLabel" runat="server" Text='<%# Eval("CategoryID") %>' />
<br />
</ItemTemplate>
</dx:ASPxDataView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT [ProductID], [ProductName], [CategoryID] FROM [Products] WHERE ([CategoryID] = @CategoryID)">
<SelectParameters>
<asp:Parameter DefaultValue="1" Name="CategoryID" Type="Int32" />
</SelectParameters>
</asp:AccessDataSource>
</form>
</body>
</html>
<%@ Page Language="vb" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v10.1, Version=10.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v10.1, Version=10.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxDataView" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v10.1, Version=10.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<!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 id="Head1" runat="server">
<title></title>
<script type="text/javascript" language="javascript">
function FocusedRowChanged(s, e) {
dataview.PerformCallback(s.GetRowKey(s.GetFocusedRowIndex()));
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource2"
KeyFieldName="CategoryID" ClientInstanceName="grid">
<SettingsBehavior AllowFocusedRow="True" />
<ClientSideEvents FocusedRowChanged="FocusedRowChanged" />
<Columns>
<dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="CategoryName" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Description" VisibleIndex="2">
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT [CategoryID], [CategoryName], [Description], [Picture] FROM [Categories]">
</asp:AccessDataSource>
</div>
<dx:ASPxDataView ID="ASPxDataView1" runat="server" ColumnCount="1" DataSourceID="AccessDataSource1"
RowPerPage="1" ClientInstanceName="dataview" OnCustomCallback="ASPxDataView1_CustomCallback"
OnLoad="ASPxDataView1_Load">
<ItemTemplate>
<b>ProductID</b>:
<asp:Label ID="ProductIDLabel" runat="server" Text='<%#Eval("ProductID")%>' />
<br />
<b>ProductName</b>:
<asp:Label ID="ProductNameLabel" runat="server" Text='<%#Eval("ProductName")%>' />
<br />
<b>CategoryID</b>:
<asp:Label ID="CategoryIDLabel" runat="server" Text='<%#Eval("CategoryID")%>' />
<br />
</ItemTemplate>
</dx:ASPxDataView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT [ProductID], [ProductName], [CategoryID] FROM [Products] WHERE ([CategoryID] = @CategoryID)">
<SelectParameters>
<asp:Parameter DefaultValue="1" Name="CategoryID" Type="Int32" />
</SelectParameters>
</asp:AccessDataSource>
</form>
</body>
</html>
Imports Microsoft.VisualBasic
Imports System
Imports System.Web.UI
Imports DevExpress.Web.ASPxDataView
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub ASPxDataView1_Load(ByVal sender As Object, ByVal e As EventArgs)
If Session("CategoryID") Is Nothing Then
Return
End If
AccessDataSource1.SelectParameters("CategoryID").DefaultValue = Session("CategoryID").ToString()
TryCast(sender, ASPxDataView).DataBind()
End Sub
Protected Sub ASPxDataView1_CustomCallback(ByVal sender As Object, ByVal e As DevExpress.Web.CallbackEventArgsBase)
Session("CategoryID") = e.Parameter
AccessDataSource1.SelectParameters("CategoryID").DefaultValue = e.Parameter
TryCast(sender, ASPxDataView).DataBind()
End Sub
End Class
See Also