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

Determine if row selected in grid via Javascript

3 Answers 196 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 03 Sep 2008, 02:19 PM
Hi,

Can anyone advise me on whether I can determine if a row is selected via Javascript in the aspx page?

Thanks in advance,

Steve

3 Answers, 1 is accepted

Sort by
0
andy
Top achievements
Rank 1
answered on 03 Sep 2008, 06:13 PM
var selecteditem = $find("<%= RadGrid1.MasterTableView.ClientID %>").get_selectedItems();

for (var i=0; i < selecteditem.length; i++)
{
     alert(selecteditem[i].getDataKeyValue('myKey'));
}
0
Kevin Babcock
Top achievements
Rank 1
answered on 03 Sep 2008, 06:29 PM
Hello Steve,

You can use the RadGrid's client-side API to retrieve its selected rows. First you need to enable client-side row selecting by setting the AllowRowSelect property to true in the <ClientSettings> of your RadGrid. Then call the get_selectedItems() function of your client-side MasterTableView object somewhere in JavaScript to get an array of the selected row's GridDataItems, which you can use for further processing. Here is a quick example:

<telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 
     
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"
    <script type="text/javascript"
        function Click() { 
            var tableView = $find('<%= RadGrid1.ClientID %>').get_masterTableView(); 
            var selectedItems = tableView.get_selectedItems(); 
            var count = selectedItems.length; 
            for (var i = 0; i < count; i++) { 
                var dataItem = selectedItems[i];                         
                // do something 
            } 
        } 
    </script> 
</telerik:RadScriptBlock> 
 
<telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowSelection="true" 
    OnNeedDataSource="RadGrid1_NeedDataSource"
    <ClientSettings> 
        <Selecting AllowRowSelect="True" /> 
    </ClientSettings> 
</telerik:RadGrid> 
 
<asp:Button ID="Button1" runat="server" 
    Text="Click Me!" 
    OnClientClick="Click(); return false;" /> 


I hope this helps. If you have further questions, please don't hesitate to ask.

Regards,
Kevin Babcock
0
Shinu
Top achievements
Rank 1
answered on 04 Sep 2008, 05:45 AM
Hi Steve,

You can also go through the following help article which explains on this regard.
Getting cell values for selected rows client side

Thanks
Shinu
Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
andy
Top achievements
Rank 1
Kevin Babcock
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Share this question
or