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

Identify radgrid row

5 Answers 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 11 Nov 2008, 05:52 PM
Hi. I was wondering if anyone could tell me how to get the index of a row that's clicked in a radgrid?

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 11 Nov 2008, 06:33 PM
Hello William,

Please try the following approaches:

1) Client side:
<ClientSettings> 
    <Selecting AllowRowSelect="True" /> 
    <ClientEvents OnRowSelected="RowSelected" /> 
</ClientSettings> 

<script type="text/javascript" language="javascript"
    function RowSelected(sender, args) 
    { 
        alert(args.get_itemIndexHierarchical()); 
    } 
</script> 

2) Server side
<ClientSettings EnablePostBackOnRowClick="true"
    <Selecting AllowRowSelect="True" /> 
</ClientSettings> 

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    if (e.CommandName == "RowClick"
    { 
        int selectedIndex = e.Item.ItemIndex; 
    } 




I hope this helps.

Kind regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
William
Top achievements
Rank 1
answered on 11 Nov 2008, 08:07 PM
Thanks Daniel, that works great.

I was wondering if you had any thoughts about this. After a button in a row is clicked, I need to access a value from the row directly above it. 

Thanks again.
0
Princy
Top achievements
Rank 2
answered on 12 Nov 2008, 04:57 AM
Hello William,

Try out the following code to access a control in the previous row when the button in a row is clicked.

cs:
protected void Button_Click(object sender, EventArgs e) 
    { 
        Button btn = (Button)sender; 
        GridDataItem dataItem = (GridDataItem)btn.NamingContainer; 
        int index = dataItem.ItemIndex; 
        string strtxt = RadGrid1.MasterTableView.Items[index - 1]["ColumnUniqueName"].Text; 
    } 

Thanks
Princy.
0
William
Top achievements
Rank 1
answered on 12 Nov 2008, 02:26 PM
Hi Princy. Thanks a lot but I'm still having a problem with this. I thought that maybe I should include some of my code.

If

 

e.CommandName = "DeleteEmployee" Then

 

Dim

 

dataItem As Telerik.Web.UI.GridDataItem = CType(e.Item, Telerik.Web.UI.GridDataItem)

 

 

Dim itemValue As String = dataItem("EmployeeID").Text

 

 

 

Dim

 

selectedIndex As Integer = e.Item.ItemIndex

 

 

Dim

 

EmpID As String = itemValue

End If

What I was hoping to do is use this from the code you provided  : 

 

Dim

 

strtxt As String = RadGrid1.MasterTableView.Items(index - 1)("EmployeeID").Text

 

 

but it's not assigning the value to strtxt

C#

 

if (e.CommandName == "DeleteEmployee")
{

 Telerik.Web.UI.GridDataItem dataItem = (Telerik.Web.UI.GridDataItem)e.Item;
 string itemValue = dataItem("EmployeeID").Text;
 int selectedIndex = e.Item.ItemIndex;
 string EmpID = itemValue;
 string strtxt = RadGrid1.MasterTableView.Items(index - 1)("EmployeeID").Text;
}

Thanks again

0
Princy
Top achievements
Rank 2
answered on 13 Nov 2008, 04:03 AM
Hello William,

Can you try replacing the last line of your code i.e.,
Dim strtxt As String = RadGrid1.MasterTableView.Items(index - 1)("EmployeeID").Text 

with the following code strip
Dim strtxt As String = RadGrid1.MasterTableView.Items(selectedIndex - 1)("EmployeeID").Text 

and see if it helps.

Thanks
Princy.

Tags
Grid
Asked by
William
Top achievements
Rank 1
Answers by
Daniel
Telerik team
William
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or