Setting GridCheckBoxColumn using JavaScript

3 posts, 0 answers
  1. Dan
    Dan avatar
    25 posts
    Member since:
    May 2008

    Posted 10 Apr 2009 Link to this post

    In our application we have a Radgrid that contains several GridBoundColumns and a few GridCheckBoxColumns. Here is the code that defines 2 of them:

     

    <telerik:GridBoundColumn

        UniqueName="gbcWBSNumber"

        DataField="WBSNumber"

        HeaderStyle-HorizontalAlign="Center"

        ItemStyle-HorizontalAlign="Center" 

        HeaderText="WBS #">

    </telerik:GridBoundColumn>

     

    <telerik:GridCheckBoxColumn

        UniqueName="gccAllowBoes"

        DataField="AllowBoes"

        HeaderStyle-HorizontalAlign="Center"

        ItemStyle-HorizontalAlign="Center" 

        HeaderText="Allow<br />BOEs">

    </telerik:GridCheckBoxColumn>  

     

     

     

    We need a way to adjust the settings of these two objects using JavaScript. We are doing this successfully for the GridBoundColumn but not for the GridCheckBoxColumn.

                          

    In the following (greatly abbreviated) JavaScript we are able to obtain a reference to both objects(stored in the  global variables WBSNumber  and AllowBOEs  respectively):

     

    function WBSGridDoubleClick(sender, eventArgs)

    {  

        (code removed…)

    WBSNumber   =     MasterTableView.getCellByColumnUniqueName(MasterTableView.get_dataItems()[index], "gbcWBSNumber");

     

    AllowBOES      = MasterTableView.getCellByColumnUniqueName(MasterTableView.get_dataItems()[index], "gccAllowBOEs");

     

          (code removed…)           

    }

     

    After some other processing we acquire new values that we need to use to reset these two objects.

     

    We have the following JavaScript code in our program to hopefully accomplish this:

     

    function OnClientCloseWBSEast(oWnd)

    {

        // call a webservice to retrieve the modified data

        WBSData.GetThisWBS(keyValues, OnGetThisWBSComplete);

    }

       

    // dt is actually an array of strings that contains the

    // information we need

    function OnGetThisWBSComplete(dt)

    {    

            WBSNumber.innerText = dt[0]; // works fine!!!

            AllowBOES.innertext = dt[4] // returns ‘true’ or ‘false’

    }

     

    Unfortunately, even though the value returned from the webservice in dt[4] reflects the latest change by the user,  the ‘innerText’ property causes the checkbox to be removed and the value ‘true’ or ‘false’ to appear in the cell.

     

    We have also tried innerHTML, value, and checked as properties for our CheckBox object but none of these work any better.

     

    Can someone tell us what the proper syntax would be?

     

    Thanks.

  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 13 Apr 2009 Link to this post

    Hi Daniel,

    You can access the value of the check box control as follows:

    AllowBOES.getElementsByTagName('input').item().checked 

    I hope this helps.

    Best Regards,
    Tsvetoslav
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dan
    Dan avatar
    25 posts
    Member since:
    May 2008

    Posted 13 Apr 2009 Link to this post

    Hi Tsvetoslav:

    Yes, thank you, your answer was absolutely correct and my checkboxes are now working!

    I did have toi make one minor adjustment to my JavaScript to interrigate the text coming back from my array of strings and set the 'checked' property of the CheckBox object to a boolean true or false... as follows;

            var strAllowBOES    = dt[3];
            if (strAllowBOES == "True")
            {
                AllowBOES.getElementsByTagName('input').item().checked = true;
            }
            else   
            {
                AllowBOES.getElementsByTagName('input').item().checked = false;
            }

    with this minor adjustment I got precisely what I was looking for.

    Thank You
Back to Top