This is a migrated thread and some comments may be shown as answers.

Getting itemindex in client-side RowDataBound event

5 Answers 324 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kalpesh
Top achievements
Rank 1
Kalpesh asked on 02 May 2012, 04:29 PM
I have a simple RadGrid where I need to create onclick attributes for various columns - these require my knowing the itemindex for the row being rendered.

Although I can find the item-index without issue with server-side binding, I am having a hard time getting the item-index with client-side binding.

I have tried various combinations of args.get_itemIndexHierarchical() with and without get_DataItem but to no avail.

I know this is probably a simple question, any ideas?

Thanks,
Motty

5 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 02 May 2012, 07:55 PM
where or when are you trying to get the index?
on an item select event
eventArgs.get_itemIndexHierarchical(); works
where eventArgs is the 2nd parameter

as in
function ItemsRowSelected(sender, eventArgs) {

where it is called
    <ClientSettings>
        <Selecting AllowRowSelect="true" />
        <ClientEvents OnRowSelected="ItemsRowSelected" />
    </ClientSettings>
0
Kalpesh
Top achievements
Rank 1
answered on 02 May 2012, 08:35 PM
I am trying to find the item-index on a RowDataBound event in JS.

function EL_OnRowDataBound(sender, args) {
.....
var boothOnClickData = 'document.location.href = "B.aspx?BoothID=' + intBoothID + '&FromPage=' + location.pathname
+ '&IndexInList=' + args.get_itemIndexHierarchical();
.....
}

This doesn't seem to work even though for the Selected event it does work.

Thanks,
Motty
0
Elliott
Top achievements
Rank 2
answered on 02 May 2012, 08:47 PM
the client API of OnRowSelected provides the index of the item

Telerik.Web.UI.GridDataItemEventArgs OnRowSelected Property

Note

To get or set property values for client API properties, you must call property accessor methods that are named with the get_ and set_ prefixes. For example, to get or set a value for a property such as cancel, you call the get_cancel or set_cancel.

This event is fired after row selection.

Fired by

RadGrid

Arguments

id - id of the RadGrid item that has raised the event

itemIndexHierarchical - hierarchical index of the item that has raised the event

gridDataItem - the corresponding data item

tableView - owner TableView of the item that has raised the event

dataKeyValues - data key value for the item that has raised the event

domEvent - dom event that was raised for the current event



the rowDataBound does not

Telerik.Web.UI.GridDataItemEventArgs OnRowDataBound Property

Note

To get or set property values for client API properties, you must call property accessor methods that are named with the get_ and set_ prefixes. For example, to get or set a value for a property such as cancel, you call the get_cancel or set_cancel.

This event will be raised for each grid item which is about to be bound on the client. Can be used to modify/extract the data from the respective row cells or apply custom formatting to some of the cells based on their values.

Fired by

RadGrid

Arguments

dataItem - the underlying data item object (equivalent to e.Item.DataItem object inside ItemDataBound on the server) item - the GridDataItem client instance which is about to be bound

maybe you can use the DataBound event for the entire grid and iterate through it?
0
Kalpesh
Top achievements
Rank 1
answered on 02 May 2012, 09:11 PM
Hi Marianne,

I can see that the documentation does not seem to point to a way to the row/item index on rowdatabound.

However, it seems weird that this would not be available in some format through the API.

If there is no API implementation, I will have to create my own counter to track the item index.

Thanks for the assistance!
Motty
0
Antonio Stoilkov
Telerik team
answered on 07 May 2012, 07:50 AM
Hi Kalpesh,

You could achieve your scenario by declaring a global variable that will track the item index. In the RowDataBound event handler iterate the variable each time as it is shown in the example below. Note that you could reset the itemIndex in the RadGrid OnDataBound client-side event.
<ClientEvents OnRowDataBound="OnRowDataBound" OnDataBound="OnDataBound" />
var itemIndex = 0;
function OnRowDataBound(sender, eventArgs)
{
    //your code logic here
    itemIndex++;
}
function OnDataBound(sender, eventArgs)
{
    itemIndex = 0;
}

Greetings,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Kalpesh
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Kalpesh
Top achievements
Rank 1
Antonio Stoilkov
Telerik team
Share this question
or