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

How to get selected row key value

1 Answer 1149 Views
Grid
This is a migrated thread and some comments may be shown as answers.
xyz
Top achievements
Rank 1
xyz asked on 27 Jan 2009, 08:14 PM
HI,
I have a radgrid. When I right click on one of the rows, I have a contextmenu. I am able to get the rowindex of a particular row through javascript. Could anyone please help me asap how to get keyvalue (either in javascript or in code behind) of a grid without having the grid in edit mode.
Thank you

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Jan 2009, 04:55 AM
Hi,

Set the ClientDataKeyNames to the desired column which you want to access the keyvalues. When you add the UniqueName of a column to the ClientDataKeyNames array of the MasterTableView or a detail GridTableView, RadGrid makes that column's value available through the getDataKeyValue() function of the GridDataItem client-side object and of the arguments for client-side event handlers that respond to item events. See the example below.

JavaScript:
function GetKeyValue(sender, eventArgs) 
    var rowindex= eventArgs.get_itemIndexHierarchical(); 
    var DataItem = $find("<%=RadGrid1.ClientID %>").get_masterTableView().get_dataItems()[rowindex]; 
    var keyValues = 'CustomerID: "' + DataItem.getDataKeyValue("CustomerID") + '"' + ' \r\n' +'CompanyName: "' + DataItem.getDataKeyValue("CompanyName") + '"'; 
    alert(keyValues);     
</script> 


ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" DataSourceID="SqlDataSource1">  
<ClientSettings> 
     <ClientEvents OnRowContextMenu="GetKeyValue" /> 
</ClientSettings> 
<MasterTableView autogeneratecolumns="False" datasourceid="SqlDataSource1" ClientDataKeyNames="CustomerID, CompanyName">  
<RowIndicatorColumn>  
<HeaderStyle Width="20px"></HeaderStyle>  
</RowIndicatorColumn>  
    <Columns>  
        <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID"   
            SortExpression="CustomerID" UniqueName="CustomerID">  
        </telerik:GridBoundColumn>  
        <telerik:GridBoundColumn DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" UniqueName="CompanyName">  
        </telerik:GridBoundColumn>  
        . . .         
    </Columns>  
</MasterTableView>  
</telerik:RadGrid>  


Thanks,
Shinu.
Sachita
Top achievements
Rank 1
Iron
Iron
Iron
commented on 01 Jul 2021, 11:27 AM

Hi ,
I am trying to select a Row and Click on it .
I have issue with the ClientEvents OnRowSelected to fetch keyvalues of a Row.
I have tried with the below code:
function RowSelected(row) {
var radWindow = Test.Utilities.WindowUtil.openRADWindow("Portlets/ConnectManager/EditFom.aspx?id=" + row.KeyValues["Guid"], "EditWindow");
radWindow.Restore();

var close = document.getElementById("CloseButton" + radWindow.Id);
close.onclick = CloseRadWindow;
}

I am getting issue with KeyValues as KeyValues is not a function and unable to readProperty 'Guid'.
Tried with GetdatakeyValue also like row.getdatakeyvalue but no luck.
Can anyone help on this?
Tags
Grid
Asked by
xyz
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or