Determine if row selected in grid via Javascript

4 posts, 0 answers
  1. Steve
    Steve avatar
    5 posts
    Member since:
    Aug 2008

    Posted 03 Sep 2008 Link to this post


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

    Thanks in advance,

  2. andy
    andy avatar
    19 posts
    Member since:
    Jun 2008

    Posted 03 Sep 2008 Link to this post

    var selecteditem = $find("<%= RadGrid1.MasterTableView.ClientID %>").get_selectedItems();

    for (var i=0; i < selecteditem.length; i++)
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kevin Babcock
    Kevin Babcock avatar
    189 posts
    Member since:
    Mar 2007

    Posted 03 Sep 2008 Link to this post

    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:

    1 <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 
    3 <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"
    4     <script type="text/javascript"
    5         function Click() { 
    6             var tableView = $find('<%= RadGrid1.ClientID %>').get_masterTableView(); 
    7             var selectedItems = tableView.get_selectedItems(); 
    8             var count = selectedItems.length; 
    9             for (var i = 0; i < count; i++) { 
    10                 var dataItem = selectedItems[i];                         
    11                 // do something 
    12             } 
    13         } 
    14     </script> 
    15 </telerik:RadScriptBlock> 
    17 <telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowSelection="true" 
    18     OnNeedDataSource="RadGrid1_NeedDataSource"
    19     <ClientSettings> 
    20         <Selecting AllowRowSelect="True" /> 
    21     </ClientSettings> 
    22 </telerik:RadGrid> 
    24 <asp:Button ID="Button1" runat="server" 
    25     Text="Click Me!" 
    26     OnClientClick="Click(); return false;" /> 

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

    Kevin Babcock
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Sep 2008 Link to this post

    Hi Steve,

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

Back to Top