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

CheckBox Client Side Question

4 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 28 Aug 2008, 09:10 PM
I have a RadGrid with a GridClientSelectColumn. 
 <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" HeaderStyle-Width="25" /> 

There is also a GridBoundColumn that I would like to access.
<telerik:GridBoundColumn SortExpression="City" HeaderText="City" HeaderButtonType="TextButton" DataField="City" /> 

If I check a couple of the checkboxes in the grid how do I get the ClientSelectColumn and the GridBoundColumn value with JavaScript using OnClientClick?

Help Please!

Thank you!

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Aug 2008, 06:38 AM
Hi George,

Set the UniqueName property for the bound column and try the following code snippet to achieve the desired scenario.

CS:
 protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            int rowIndx = item.ItemIndex; 
            CheckBox chkbx = (CheckBox)item["ClientSelectColumn"].Controls[0]; 
            chkbx.Attributes.Add("OnClick", "return Show('" + rowIndx + "');"); 
 
        } 
    } 

JS:
 <script type="text/javascript" language="javascript" > 
          
         function Show(rowIndx) 
         { 
          var grid = $find("<%=RadGrid2.ClientID %>"); 
          var MasterTable = grid.get_masterTableView(); 
          
         var row = MasterTable.get_dataItems()[rowIndx]; 
          
         var cell = MasterTable.getCellByColumnUniqueName(row, "City"); 
         alert(cell.innerHTML)   
         } 
 
 </script > 
 


Thanks
Shinu.
0
Mike
Top achievements
Rank 1
answered on 29 Aug 2008, 12:20 PM
I like this approach, but I want to loop through all the checked items when someone hits the submit button. 

This works just dandy! But I need the alert to have "Yes" and "Cancel" buttons.  Currently the alert only has a "Yes" :(
   function Click()        
        {           
            var grid = $find("<%=RadGrid1.ClientID %>");                            
            var selectedUniqueNames = "";         
            var gridgridSelectedItems = grid.get_masterTableView().get_selectedItems();             
            for (var i=0; i<gridSelectedItems.length; i++)          
            {               
                selectedUniqueNames += "Priority " + gridSelectedItems[i].getDataKeyValue("Row") + " User " + gridSelectedItems[i].getDataKeyValue("City") + "\n";            
            }           
            alert(selectedUniqueNames);     
            return false;   
          }        
0
Shinu
Top achievements
Rank 2
answered on 01 Sep 2008, 10:13 AM
Hi George,

Try setting the confirm message instead of alert as shown below.

JS:
function Click()         
        {            
            var grid = $find("<%=RadGrid1.ClientID %>");                             
            var selectedUniqueNames = "";          
            var gridgridgridSelectedItems = grid.get_masterTableView().get_selectedItems();              
            for (var i=0; i<gridSelectedItems.length; i++)           
            {                
                selectedUniqueNames += "Priority " + gridSelectedItems[i].getDataKeyValue("Row") + " User " + gridSelectedItems[i].getDataKeyValue("City") + "\n";             
            }            
            confirm(selectedUniqueNames);      
            return false;    
          }     


Thanks
Shinu.
0
Mike
Top achievements
Rank 1
answered on 02 Sep 2008, 12:03 PM
Great, I did that but the form still submits even when I click on the cancel button. :(
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mike
Top achievements
Rank 1
Share this question
or