I have a RadGrid with an OnRowDbClick method set.
This is the code from inside the grid
<
ClientSettings
EnablePostBackOnRowClick
=
"true"
>
<
Selecting
AllowRowSelect
=
"True"
/>
<
ClientEvents
OnRowDblClick
=
"RowDblClick"
/>
</
ClientSettings
>
In the RowDblClick method I get the item index like this.
function RowDblClick(sender, eventArgs) {
var i = eventArgs.get_itemIndexHierarchical();
// rest of this method removed for brevity.
}
This works.
Now elsewhere on this page I have a simple button.
<
input
type
=
"button"
value
=
"Select"
onclick
=
"SetupPageIndexing()"
/>
function SetupPageIndexing() {
// ??
}
The button is not part of the grid. It's just a button.
I gave it an OnClick event method however how do I get this
eventArgs.get_itemIndexHierarchical()
value? eventArgs is not a property of my buttons click event and as it is not related to the grid in anyway, I can't see how to get this value. 6 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 14 Jul 2011, 08:10 AM
Hello Brad,
OnRowDblClick has two default arguments, sender and eventArgs. So you can directly access the row using these properties. Since the button is outside the grid, you cannot set default parameters. Here is a sample code to access the griditem in a button click.
Javascript:
Thanks,
Shinu.
OnRowDblClick has two default arguments, sender and eventArgs. So you can directly access the row using these properties. Since the button is outside the grid, you cannot set default parameters. Here is a sample code to access the griditem in a button click.
Javascript:
<script type=
"text/javascript"
>
function
SetupPageIndexing()
{
var
grid = $find(
"<%=RadGrid1.ClientID %>"
);
var
masterTable = grid.get_masterTableView();
var
row = masterTable.get_dataItems()[2];
}
</script>
Thanks,
Shinu.
0

Brad
Top achievements
Rank 1
answered on 14 Jul 2011, 11:55 PM
Shinu
My goal is get the row index of the currently selected row. Not set default parameters of anything.
I ran your code and at the end I did this.
Not surprisingly it equals 'Object'.
In need the integer row index. Just like what I get in the RowDblClick event with this line.
Difference being that 'eventArgs' does not exist in my button's click event. How do I get the
Sorry if I was not clear.
My goal is get the row index of the currently selected row. Not set default parameters of anything.
I ran your code and at the end I did this.
alert(grid.get_dataItems()[2]);
Not surprisingly it equals 'Object'.
In need the integer row index. Just like what I get in the RowDblClick event with this line.
var i = eventArgs.get_itemIndexHierarchical();
Difference being that 'eventArgs' does not exist in my button's click event. How do I get the
itemIndexHierarchical
value in this case?Sorry if I was not clear.
0

Princy
Top achievements
Rank 2
answered on 15 Jul 2011, 06:58 AM
Hello Brad,
I suppose you want to get the count of selected items in a button click. Try the following code snippet to get the count of selected items.
aspx:
Javascript:
Thanks,
Princy.
I suppose you want to get the count of selected items in a button click. Try the following code snippet to get the count of selected items.
aspx:
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Get Count"
OnClientClick
=
"GetSelectedItems(); return false;"
/>
Javascript:
<script type=
"text/javascript"
>
function
GetSelectedItems()
{
alert($find(
"<%= RadGrid1.MasterTableView.ClientID %>"
).get_selectedItems().length);
}
</script>
Thanks,
Princy.
0

Brad
Top achievements
Rank 1
answered on 15 Jul 2011, 07:08 AM
Ummm.. no. I want the index of the selected row. On my grid only one row can be selected at a time. I just need to know it's index position in the grid.
This is what
. . .gives me in the rows double click event (where eventArgs is available and contain the value I need). Just need that value in an button's click event where the button does not have any relationship to the grid (other than the fact they are on the same page)
This is what
eventArgs.get_itemIndexHierarchical();
. . .gives me in the rows double click event (where eventArgs is available and contain the value I need). Just need that value in an button's click event where the button does not have any relationship to the grid (other than the fact they are on the same page)
0
Accepted

Shinu
Top achievements
Rank 2
answered on 15 Jul 2011, 10:10 AM
Hello Brad,
You can use _itemIndexHierarchical to get the index.
Javascript:
Thanks,
Shinu.
You can use _itemIndexHierarchical to get the index.
Javascript:
function
ButtonClick()
{
var
grid = $find(
"<%=RadGrid1.ClientID %>"
);
var
masterTable = grid.get_masterTableView();
alert(masterTable.get_selectedItems()[0]._itemIndexHierarchical);
}
Thanks,
Shinu.
0

Brad
Top achievements
Rank 1
answered on 17 Jul 2011, 11:44 PM
Thanks Shinu... It is fixed.