Hi Telerik,
If a grid has detail table, the client grid command is set, the ItemCommand of the detail table will get the incorrect GridDataItem, can you take a look?
In following example, click "Remove" button on the row other than the first row in the detail table will get the wrong GridDataItem, the item of first row is always returned.
If the client event is disabled, the ItemCommand will work correctly.
Default.aspx
Default.aspx.cs
If a grid has detail table, the client grid command is set, the ItemCommand of the detail table will get the incorrect GridDataItem, can you take a look?
<ClientSettings> <ClientEventsOnCommand="GridCommand"/></ClientSettings>protectedvoidRadGrid1_ItemCommand (objectsender, GridCommandEventArgs e){ if(e.CommandName == "RemoveLogin") { GridDataItem item = (GridDataItem)e.Item; intdeleteKey = Convert.ToInt32 (item["KeyID"].Text); Label1.Text = item["KeyID"].Text + "<br/>"+ item["LoginID"].Text; //RadGrid1.Rebind (); }}In following example, click "Remove" button on the row other than the first row in the detail table will get the wrong GridDataItem, the item of first row is always returned.
If the client event is disabled, the ItemCommand will work correctly.
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"> <title></title> <telerik:RadStyleSheetManagerID="RadStyleSheetManager1"runat="server"/></head><body> <formid="form1"runat="server"> <telerik:RadScriptManagerID="RadScriptManager1"runat="server"> <Scripts> <asp:ScriptReferenceAssembly="Telerik.Web.UI"Name="Telerik.Web.UI.Common.Core.js"/> <asp:ScriptReferenceAssembly="Telerik.Web.UI"Name="Telerik.Web.UI.Common.jQuery.js"/> <asp:ScriptReferenceAssembly="Telerik.Web.UI"Name="Telerik.Web.UI.Common.jQueryInclude.js"/> </Scripts> </telerik:RadScriptManager> <scripttype="text/javascript"> function GridCommand(sender, eventArgs) { } </script> <telerik:RadAjaxManagerID="RadAjaxManager1"runat="server"> </telerik:RadAjaxManager> <div> <telerik:RadGridID="RadGrid1"AutoGenerateColumns="False"runat="server"AllowSorting="True"CellSpacing="0"GridLines="None"AllowPaging="True"PageSize="20" OnDetailTableDataBind="RadGrid1_DetailTableDataBind"OnItemCommand="RadGrid1_ItemCommand"OnNeedDataSource="RadGrid1_NeedDataSource"> <SortingSettingsEnableSkinSortStyles="false"/> <ClientSettings> <SelectingAllowRowSelect="True"/> <ClientEventsOnCommand="GridCommand"/> </ClientSettings> <GroupingSettingsCaseSensitive="false"/> <MasterTableViewDataKeyNames="MemberID"ClientDataKeyNames="MemberID"AllowFilteringByColumn="True"> <DetailTables> <telerik:GridTableViewName="KeyDetail"Width="100%"> <Columns> <telerik:GridBoundColumnDataField="KeyID"ReadOnly="true"HeaderText="Login ID"UniqueName="KeyID"AllowFiltering="false"/> <telerik:GridBoundColumnDataField="LoginID"ReadOnly="true"HeaderText="Login"UniqueName="LoginID"AllowFiltering="false"/> <telerik:GridBoundColumnDataField="LoginSID"ReadOnly="true"HeaderText="Encrypted SID"UniqueName="LoginSID"AllowFiltering="false"/> <telerik:GridButtonColumnUniqueName="RemoveLogin"ButtonType="PushButton"HeaderText=""CommandName="RemoveLogin"Text="Remove"/> </Columns> </telerik:GridTableView> </DetailTables> <Columns> <telerik:GridBoundColumnDataField="FirstName"ReadOnly="true"HeaderText="First Name"UniqueName="FirstName"ShowFilterIcon="false"AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"/> <telerik:GridBoundColumnDataField="LastName"ReadOnly="true"HeaderText="Last Name"UniqueName="LastName"ShowFilterIcon="false"AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"/> <telerik:GridButtonColumnUniqueName="EditLink"ButtonType="PushButton"HeaderText="Edit User"CommandName="EditUser"Text="Edit"/> <telerik:GridButtonColumnUniqueName="ViewLog"ButtonType="PushButton"HeaderText="View Log"CommandName="ViewLog"Text="Log"/> </Columns> <PagerStyleMode="NextPrevNumericAndAdvanced"AlwaysVisible="true"/> <SortExpressions> <telerik:GridSortExpressionFieldName="userActive"SortOrder="Descending"/> </SortExpressions> </MasterTableView> </telerik:RadGrid> <p> <asp:LabelID="Label1"runat="server"Text="Message"></asp:Label> </p> </div> </form></body></html>Default.aspx.cs
usingSystem;usingSystem.Data;usingTelerik.Web.UI;publicpartialclassDefault : System.Web.UI.Page{ protectedvoidPage_Load (objectsender, EventArgs e) { if(!IsPostBack) { DataTable masterTable = newDataTable (); masterTable.Columns.Add (newDataColumn ("FirstName", Type.GetType ("System.String"))); masterTable.Columns.Add (newDataColumn ("LastName", Type.GetType ("System.String"))); masterTable.Columns.Add (newDataColumn ("MemberID", Type.GetType ("System.Int32"))); masterTable.Columns.Add (newDataColumn ("userActive", Type.GetType ("System.Boolean"))); masterTable.Rows.Add ("John", "Doe", 1, true); masterTable.Rows.Add ("Sam", "Smith", 2, false); masterTable.Rows.Add ("Mary", "Doe", 3, true); DataTable detailTable = newDataTable (); detailTable.Columns.Add (newDataColumn ("MemberID", Type.GetType ("System.Int32"))); detailTable.Columns.Add (newDataColumn ("KeyID", Type.GetType ("System.String"))); detailTable.Columns.Add (newDataColumn ("LoginID", Type.GetType ("System.String"))); detailTable.Columns.Add (newDataColumn ("LoginSID", Type.GetType ("System.String"))); detailTable.Rows.Add (1, "1001", "Office\\JD", "JohnDoeSID"); detailTable.Rows.Add (1, "1002", "Home\\JD", "JohnDoeSID2"); detailTable.Rows.Add (1, "1003", "Home\\JD2", "JohnDoeSID3"); detailTable.Rows.Add (2, "2001", "Office\\SS", "SamSmithSID"); detailTable.Rows.Add (2, "2002", "Home\\SS", "SamSmithSID2"); ViewState["master"] = masterTable; ViewState["detail"] = detailTable; } } protectedvoidRadGrid1_NeedDataSource (objectsender, GridNeedDataSourceEventArgs e) { RadGrid1.DataSource = (DataTable)ViewState["master"]; } protectedvoidRadGrid1_DetailTableDataBind (objectsender, GridDetailTableDataBindEventArgs e) { GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem; if(e.DetailTableView.Name == "KeyDetail") { stringmemberID = dataItem.GetDataKeyValue ("MemberID").ToString (); DataTable detailTable =(DataTable)ViewState["detail"]; e.DetailTableView.DataSource = detailTable.Select ("MemberID ="+ memberID); } } protectedvoidRadGrid1_ItemCommand (objectsender, GridCommandEventArgs e) { if(e.CommandName == "RemoveLogin") { GridDataItem item = (GridDataItem)e.Item; intdeleteKey = Convert.ToInt32 (item["KeyID"].Text); Label1.Text = item["KeyID"].Text + "<br/>"+ item["LoginID"].Text; //RadGrid1.Rebind (); } }}