Hi,
I've pasted my code below. I need to know which row caused the itemcommand server side. This works fine in below code as long as the OnCommand client event is not used. When i start using it the ItemIndex is always 0. The same issue is described in http://www.telerik.com/community/forums/aspnet-ajax/grid/itemcommand-why-is-my-itemindex-always-zero.aspx, but the solution does not work for me as the selected row might be different. GetDataKeyValue also does not work it always returns the data key from first row.
Is there a way to find which row caused the itemcommand while have the client side OnCommand?
Thanks!
I've pasted my code below. I need to know which row caused the itemcommand server side. This works fine in below code as long as the OnCommand client event is not used. When i start using it the ItemIndex is always 0. The same issue is described in http://www.telerik.com/community/forums/aspnet-ajax/grid/itemcommand-why-is-my-itemindex-always-zero.aspx, but the solution does not work for me as the selected row might be different. GetDataKeyValue also does not work it always returns the data key from first row.
Is there a way to find which row caused the itemcommand while have the client side OnCommand?
Thanks!
using
System;
using
Telerik.Web.UI;
public
partial
class
Default : System.Web.UI.Page
{
public
class
A
{
public
int
a {
get
;
set
; }
public
int
b {
get
;
set
; }
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
RadGrid1.DataSource =
new
A[] {
new
A() {a = 1, b = 2},
new
A() {a = 3, b = 4}};
}
protected
void
rg_ItemCommand(
object
sender, GridCommandEventArgs e)
{
int
i = e.Item.ItemIndex;
GridDataItem item = (GridDataItem)e.Item;
int
letterId = (
int
)item.GetDataKeyValue(
"a"
);
//GridDataItem dataItem = RadGrid1.SelectedItems[0] as GridDataItem;
}
}
<%@ 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">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
<
telerik:RadStyleSheetManager
ID
=
"RadStyleSheetManager1"
runat
=
"server"
/>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
<
Scripts
>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI, Version=2012.3.1205.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"
Name
=
"Telerik.Web.UI.Common.Core.js"
/>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI, Version=2012.3.1205.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"
Name
=
"Telerik.Web.UI.Common.jQuery.js"
/>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI, Version=2012.3.1205.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"
Name
=
"Telerik.Web.UI.Common.jQueryInclude.js"
/>
</
Scripts
>
</
telerik:RadScriptManager
>
<
script
type
=
"text/javascript"
>
//Put your JavaScript code here.
</
script
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
</
telerik:RadAjaxManager
>
<
div
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
OnItemCommand
=
"rg_ItemCommand"
>
<
MasterTableView
DataKeyNames
=
"a"
AutoGenerateColumns
=
"False"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"a"
DataType
=
"System.Int32"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"b"
DataType
=
"System.Int32"
>
</
telerik:GridBoundColumn
>
<
telerik:GridButtonColumn
ButtonType
=
"LinkButton"
CommandName
=
"test"
Text
=
"test"
>
</
telerik:GridButtonColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
>
<%--removing Oncommand will make itemindex work--%>
<
ClientEvents
OnCommand
=
"rgCommand"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
</
div
>
<
script
type
=
"text/javascript"
>
function rgCommand(sender, args) {
var commandName = args.get_commandName();
}
</
script
>
</
form
>
</
body
>
</
html
>