9 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 05 Jan 2010, 02:20 PM
Hello Sree,
Try out the following code to get the currently selected item:
c#:
Thanks
Princy.
Try out the following code to get the currently selected item:
c#:
| protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e) |
| { |
| GridDataItem dataItem = (GridDataItem)RadGrid1.SelectedItems[RadGrid1.SelectedItems.Count - 1]; |
| string ID = dataItem.GetDataKeyValue("ID").ToString(); |
| } |
Thanks
Princy.
0
Hi Sree,
You could get all selected indexes from the grid SelectedIndexes property. It is a collection which holds all selected row indexes. If you want to get the last selected row index you can use the following code snippet for instance:
Additionally I am sending you a simple example demonstrating how to achieve the desired functionality.
I hope this helps.
Best wishes,
Radoslav
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
You could get all selected indexes from the grid SelectedIndexes property. It is a collection which holds all selected row indexes. If you want to get the last selected row index you can use the following code snippet for instance:
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e){ int lastSelectedIndex = Convert.ToInt32(RadGrid1.SelectedIndexes[RadGrid1.SelectedIndexes.Count - 1]);}Additionally I am sending you a simple example demonstrating how to achieve the desired functionality.
I hope this helps.
Best wishes,
Radoslav
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Sree
Top achievements
Rank 1
answered on 06 Jan 2010, 04:47 AM
Hi Radoslav
Thanks for your help,but it doesn't solve my problem.I have grid with multiple selected rows(AllowMultiRowSelection="True").In your example you are always taking the selectedindexesitems[0] .It will work since there is only one selected row.In my case I have multiple selected rows and I can select the rows in any order.So please suggest a solution for this.
Thanks for your help,but it doesn't solve my problem.I have grid with multiple selected rows(AllowMultiRowSelection="True").In your example you are always taking the selectedindexesitems[0] .It will work since there is only one selected row.In my case I have multiple selected rows and I can select the rows in any order.So please suggest a solution for this.
0
Shinu
Top achievements
Rank 2
answered on 06 Jan 2010, 05:04 AM
Hello Sree,
You can loop through the SelectedItems collection of RadGrid in order to get the corresponding indexes, as shown below.
CS:
-Shinu.
You can loop through the SelectedItems collection of RadGrid in order to get the corresponding indexes, as shown below.
CS:
| protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e) |
| { |
| foreach (GridDataItem item in RadGrid1.SelectedItems) |
| { |
| string CustID = item.GetDataKeyValue("CustomerID").ToString(); |
| Response.Write(CustID); |
| } |
| } |
-Shinu.
0
Sree
Top achievements
Rank 1
answered on 06 Jan 2010, 05:54 AM
Hi
Thanks to all..At last I have found a solution
In gridview's ItemCommand event we can get the current row index as given below.
protected void gv_ItemCommand(object source, GridCommandEventArgs e)
{
Session["RowIndex"] = e.Item.ItemIndex.ToString();
}
protected void gv_SelectedIndexChanged(object sender, EventArgs e)
{
var CurrentSelectedRowIndex=Session["RowIndex"]
}
Thanks to all..At last I have found a solution
In gridview's ItemCommand event we can get the current row index as given below.
protected void gv_ItemCommand(object source, GridCommandEventArgs e)
{
Session["RowIndex"] = e.Item.ItemIndex.ToString();
}
protected void gv_SelectedIndexChanged(object sender, EventArgs e)
{
var CurrentSelectedRowIndex=Session["RowIndex"]
}
0
THANGARAI
Top achievements
Rank 1
answered on 04 Apr 2014, 05:32 AM
Hi Princy,
How do I get a gridrow by its index in telerik radgrid without loop.?
How do I get a gridrow by its index in telerik radgrid without loop.?
0
Princy
Top achievements
Rank 2
answered on 04 Apr 2014, 06:06 AM
Hi Thangarai,
I guess you want to access the currently selected row's index. Please try the following code snippet. If this doesn't help, elaborate on your requirement.
ASPX:
C#:
Thanks,
Princy
I guess you want to access the currently selected row's index. Please try the following code snippet. If this doesn't help, elaborate on your requirement.
ASPX:
<ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true"></ClientSettings>C#:
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e){ GridDataItem selectedItem = (GridDataItem)RadGrid1.SelectedItems[0]; int index = selectedItem.ItemIndex;// Gets the index of currently selected row}Thanks,
Princy
0
THANGARAI
Top achievements
Rank 1
answered on 04 Apr 2014, 06:15 AM
Hi Princy,
Thanks for your reply.
I think the above code is for single row select. I have scenario to select multiple row by checking a CHECKBOX,
and I should get all the selected row values where the checkbox is checked.
Note: Please find the attachment.
Thanks for your reply.
I think the above code is for single row select. I have scenario to select multiple row by checking a CHECKBOX,
and I should get all the selected row values where the checkbox is checked.
Note: Please find the attachment.
0
Princy
Top achievements
Rank 2
answered on 07 Apr 2014, 04:08 AM
Hi Thangarai,
Since you want to get all the selected rows, we have to loop through the rows to identify the selected rows and get its index.
C#:
Thanks,
Princy
Since you want to get all the selected rows, we have to loop through the rows to identify the selected rows and get its index.
C#:
foreach (GridDataItem selectedItem in RadGrid1.SelectedItems){ int index = selectedItem.ItemIndex; }Thanks,
Princy
