Hello,
I have a RadGrid which one of its columns is RadCombobox.
when i change item in one of the comboboxes, i want to know to which item (row) in the grid it belongs.
I mean, I want to know which of the rows was changed
How do i do that?
i thought to do it in the radCombobox 'OnClientSelectedIndexChanged' event,
but i dont know how to get to check which row i changed.
it's very important for me.
waiting for an answer,
yoni
4 Answers, 1 is accepted

The RadControls expects only two parameters as its arguments, sender and arguments. You cannot pass the extra arguments directly.
The easiest way to pass predefined parameters to a function executed on the clientside, is to assign anonymous function and pass the parameters:
Here is a sample code.
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditFormItem && e.Item.IsInEditMode)
{
GridEditFormItem item = (GridEditFormItem)e.Item;
RadComboBox combo = (RadComboBox)item.FindControl(
"RadCombo"
);
combo.OnClientSelectedIndexChanged =
"function (button,args){OptionSelected('"
+ editItem.ItemIndex +
"');}"
;
}
}
Javascript:
function
OptionSelected(rowIndex)
{
alert(rowIndex);
}
Another approach is to add attribute for the Radcombo and get the attribute from the OnClientSelectedIndexChanged event like below.
C#:
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditFormItem && e.Item.IsInEditMode)
{
GridEditFormItem item = (GridEditFormItem)e.Item;
combo .OnClientSelectedIndexChanged =
"OptionSelected"
;
combo .Attributes.Add(
"Index"
, editItem.ItemIndex);
}
}
Javascript:
function
QuoteOptionSelected(sender, args)
{
alert(sender.get_attributes().getAttribute(
"Index"
));
//retrieving attribute with the attribute name
}
Thanks,
Shinu.

Thank you so much!
it helped me !!
i hope it's ok if i ask you another question:
my grid (8 items) is with paging (PageSize = 5),
but i have two problems:
1) when i do 'for each' on the grid items , the "RadGrid1.Items.Count" equals - 5 and not 8
and then i get a message:
"index was out of range. must be non negative and less then the size of the collection. parameter name : index"
2) when i add a new record - i dont see it because it's at an other page,
how can i make it go to the last page - where the new item is?

Hello Shinu,
you helped me alot.
i have a problem with this code:
instead of this - editItem.ItemIndex
i want to write this-
editItem.ItemIndex + (RadGrid1.PageSize * (RadGrid1.CurrentPageIndex))
because if, let's say, i am adding a new record when i am at the last page, the 'editItem.itemIndex' will be the index of the item in the current page.
(if we have 8 items, and the pageSize is 5, and i'm at the second page, adding the 9'th item, the 'editItem.itemIndex' equals 4 instead of 9)
that's why i want to write the code above.
now my problem is, in this event (itemCreated) the RadGrid1.CurrentPageIndex does not change yet to the right page, it's still shows the prev page.
how can i get the right current page?
thank in advance,
yoni
You do not have access to items in other pages in RadGrid. Only items in the current page are initialized. Therefore, no item exists for item index greater than your PageSize -1. Even if you are on, let's say, the 3rd page and your PageSize = 5, your item indexes still range from 0 to 4. As for inserting an item in a page that is not currently shown, you cannot access this new item before you have changed the grid page. So, if you need to show the last inserted item and you know it is added to the end of the items list, you need to change the CurrentPageIndex to the last page and then rebind. This will have RadGrid show the last page. Another thing you can try is setting
RadGrid1.MasterTableView.InsertItemPageIndexAction = GridInsertItemPageIndexAction.ShowItemOnLastPage = true;
This will have RadGrid automatically go to the last page when you click the Add New record button in the command item and the insert form is shown. Thus, when your new item is inserted, it will be shown in the current page, because the grid is already on the last page.
Greetings,
Veli
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.