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

Cannot get 'OnRowSelected' to fire with Select Button

4 Answers 171 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard M
Top achievements
Rank 1
Richard M asked on 13 May 2010, 06:15 PM
I have a RadGrid with a GridButtonColumn containing a Select button, CommandName="Select".  In the the RadGrid's <Client Events> I added 'OnRowSelected' = "myFunction()".  I want to be able to click on the Select button and trigger the OnRowSelected event to use my Javascript function.  But this is not working.  Here is my code:

 

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
    function myFunction()
    {
      alert('testing');
    }
    </script>
    </telerik:RadCodeBlock>

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="SqlDataSource1" GridLines="None">
    <HeaderContextMenu EnableAutoScroll="True">
    </HeaderContextMenu>
    <MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
    <RowIndicatorColumn>
    <HeaderStyle Width="20px" />
    </RowIndicatorColumn>
    <ExpandCollapseColumn>
    <HeaderStyle Width="20px" />
    </ExpandCollapseColumn>
    <Columns>
    <telerik:GridButtonColumn CommandName="Select" Text="Select" UniqueName="column">
    </telerik:GridButtonColumn>
    </Columns>
    </MasterTableView>
    <ClientSettings  Selecting-AllowRowSelect="true">
    <Selecting AllowRowSelect="true" />
   <ClientEvents OnRowSelected="myFunction" />
    </ClientSettings>
    </telerik:RadGrid>

 

 

 

 

 

 

 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 May 2010, 07:21 AM

Hi Richard,

Normally when you add GridButtoncolumn with CommandName "Select", the OnRowSelect will not invoked.But you can attach the OnCommand event and check for the CommandName in the handler to perform the actions when a selection is made.

JavaScript:

 
    <script type="text/javascript">  
        function myFunction(sender, args) {  
            if (args.get_commandName() == "Select") {  
                // Your code  
                alert('testing');  
            }  
        }  
    </script> 

[args.get_commandArgument() stores item index. Thus you can use it to access clicked data item]

-Shinu.

0
Richard M
Top achievements
Rank 1
answered on 18 May 2010, 10:19 PM
That worked great.  What I am trying to do now is get the value of the column 'ID' when I click on the Select button, which I can then pass to a RadWindow.  I tried using the code below with <ClientEvents OnCommand="rowSelected" />, but I get the error 'Microsoft JScript runtime error: Object doesn't support this property or method'.

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="SqlDataSource1" GridLines="None" AllowAutomaticDeletes="True">
    <HeaderContextMenu EnableAutoScroll="True">
    </HeaderContextMenu>
    <MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSource1" CommandItemDisplay="Top" DataKeyNames="ID"
    ClientDataKeyNames="ID">
    <Columns>
    <telerik:GridButtonColumn CommandName="Select" Text="Select" UniqueName="column" >
    </telerik:GridButtonColumn>
    </Columns>
    </MasterTableView>
    <ClientSettings>
    <ClientEvents OnCommand="rowSelected" />
    </ClientSettings>
    </telerik:RadGrid>

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
    function rowSelected(sender, eventArgs) {
        if (eventArgs.get_commandName() == "Select") {
            var ID = eventArgs.getDataKeyValue("ID")
            alert(ID);
        }
    }
    </script>
    </telerik:RadCodeBlock>

0
Shinu
Top achievements
Rank 2
answered on 19 May 2010, 11:26 AM
Hello Richanrd,

Try the following client side code in order to access the datakeyvalue in OnCommand client event.

javascript:
 
    <script type="text/javascript"
        function myFunction(sender, args) { 
            if (args.get_commandName() == "Select") { 
                var DataItem = $find("<%=RadGrid1.ClientID %>").get_masterTableView().get_dataItems()[args.get_commandArgument()]; 
                var keyValues = DataItem.getDataKeyValue("ID"); 
                alert(keyValues); 
            } 
        } 
    </script> 

Hope this helps,
Shinu
0
Richard M
Top achievements
Rank 1
answered on 20 May 2010, 05:57 PM
Shinu,
That works great!  Thank you very much for all your help.

Richard
Tags
Grid
Asked by
Richard M
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Richard M
Top achievements
Rank 1
Share this question
or