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

Javascript to get number of checkboxes checked in radgrid

3 Answers 482 Views
Grid
This is a migrated thread and some comments may be shown as answers.
LUCKY
Top achievements
Rank 1
LUCKY asked on 11 Mar 2008, 01:06 PM
Hi,

I have a GridClientSelectColumn in my rad grid. In my CommandItemTemplate I have a link button called view.

Now wat i want is on click of the view button, I need to iterate through the rows in my grid and check that only one checkbox is selected in the GridClientSelectColumn.

Regards

3 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 13 Mar 2008, 02:55 PM
Hi,

you can simply check whether an item is selected or not. This may look something like this:

.aspx
<telerik:RadGrid   
         ID="RadGrid1" runat="server" DataSourceID="AccessDataSource1" GridLines="None" 
         AllowMultiRowSelection="true">  
            <ExportSettings> 
                <Pdf FontType="Subset" PaperSize="Letter" /> 
                <Excel Format="Html" /> 
                <Csv ColumnDelimiter="Comma" RowDelimiter="NewLine" /> 
            </ExportSettings> 
            <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Top" CurrentResetPageIndexAction="SetPageIndexToFirst"               
                DataKeyNames="CustomerID" DataSourceID="AccessDataSource1" Dir="LTR" Frame="Border" 
                TableLayout="Auto">  
                  
                <CommandItemTemplate> 
                <asp:Button runat="server" ID="button1" OnClientClick="getSelected();" Text="getSelected" />                  
                </CommandItemTemplate> 

.Js
 <script type="text/javascript">  
      
        function getSelected()  
        {  
        var RadGrid1 = $find("<%=RadGrid1.ClientID %>");  
        alert("Number of selected items : " + RadGrid1.get_masterTableView().get_selectedItems().length);  
        }  
      
        </script> 

I hope this information helps.

All the best,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
ratheesh
Top achievements
Rank 1
answered on 17 Mar 2009, 06:26 AM
hi ,
i have a rad grid with a template column with a checkbox

1) i want to get the number of rows in a rad grid in client side and check how many checkbox are selected
if selected need to execute some server side  code
else need to return an alert box saying 'please select a id to remove'

2) i have a scenario where a user will add a row to the rad grid and once added that newly added row has to be slected.
i want to do this on client or server side

 function getSelected()  
        {  
        var RadGrid1 = $find("<%=RadGrid1.ClientID %>");  
        alert("Number of selected items : " + RadGrid1.get_masterTableView().get_selectedItems().length);  
        }  
i tried this but the return value is only 0


0
Yavor
Telerik team
answered on 19 Mar 2009, 10:12 AM
Hello ratheesh,

Basically, the approach which I mentioned previously is applicable if checking the checkbox will trigger some selection in the control.
If this is not the case, you can reference the cell which would contain the checkbox, and then the checkbox itself to get its value.
Additionally, you can preselect the newly added item in the grid, in the PreRender server side handler, by Accessing RadGrid1.MasterTableView.Items[x], where x is the index of the newly entered item.
I hope this helps.

Regards,
Yavor
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
LUCKY
Top achievements
Rank 1
Answers by
Yavor
Telerik team
ratheesh
Top achievements
Rank 1
Share this question
or