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

clientside check a checkbox in grid

1 Answer 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
wmj
Top achievements
Rank 1
wmj asked on 11 May 2017, 09:52 PM

I've got a drop down list and when a particular item is selected I'd like to check a checkbox inside a radgrid. below is what I've figured out thus far but can't quite figure out how to check the checkbox.

 

<script type="text/javascript">
        function OnClientItemSelected(sender, eventArgs) {
            var item = eventArgs.get_item(); //target 3

            var grid = $find("<%= rgClientSites.ClientID %>");
            var masterTable = grid.get_masterTableView();
            var cell = masterTable.getCellByColumnUniqueName(masterTable.get_dataItems()[0], "2"); //2 is the item that contains the checkbox

            if (item.get_value() === "3") {
                //check it
                alert(cell.innerHTML); 
            }
            else {
                //uncheck it

            }

        }
</script>

 

Any help would be most appreciated.

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Loïc
Top achievements
Rank 1
answered on 12 May 2017, 09:03 AM

Hi wmj,

What is your RadGridColumn type ? Is it a GridTemplateColumn ?

In this case, you could do something like this :

ASPX :

<telerik:RadGrid ID="rgClientSites" runat="server">
  <MasterTableView>
    <Columns>
      <telerik:GridTemplateColumn HeaderText="Check" UniqueName="columnCheck"
        <ItemTemplate
          <asp:CheckBox ID="CheckBox1" runat="server" /> 
        </ItemTemplate
      </telerik:GridTemplateColumn>
    </Columns
  </MasterTableView>
</telerik:RadGrid>

 

JavaScript :

function OnClientItemSelected(sender, eventArgs) {
  var item = eventArgs.get_item(); //target 3
 
  var grid = $find("<%= rgClientSites.ClientID %>");
  var masterTable = grid.get_masterTableView();
  var gridCheckItem = masterTable.get_dataItems()[0].findElement("CheckBox1");
 
  if (item.get_value() === "3") {
    //check it
    gridCheckItem.checked = true;
  }
  else {
    //uncheck it
    gridCheckItem.checked = false;
  }
}

 

Let me know if you have any other questions.

Tags
Grid
Asked by
wmj
Top achievements
Rank 1
Answers by
Loïc
Top achievements
Rank 1
Share this question
or