how to get checkbox column value in unbound mode

4 posts, 0 answers
  1. Igor Ashmetkov
    Igor Ashmetkov avatar
    12 posts
    Member since:
    Oct 2008

    Posted 28 Jun 2013 Link to this post

            Hello!
    I have RadGrid which is bound to DataSource, and one of my column (GridCheckBoColumn) is unbound.
    I want to to get column value on client side:

    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" PageSize="40"  CellSpacing="0" DataSourceID="entityDsAutoJoinLog" GridLines="None" Height="100%"  OnItemDataBound="RadGrid1_ItemDataBound"
             AllowAutomaticUpdates="true" >
    <ClientSettings EnableRowHoverStyle="true" >
        <Scrolling AllowScroll="true" UseStaticHeaders="true" />
    </ClientSettings>
              
    <MasterTableView AutoGenerateColumns="False" DataKeyNames="CLIENT_CLASS, KEY_VALUE" DataSourceID="entityDsAutoJoinLog" >
        <Columns>  
     <telerik:GridCheckBoxColumn UniqueName="Parent"  />
    ...


    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    CheckBox chkBoxParent = (CheckBox)dataBoundItem["Parent"].Controls[0];
                    chkBoxParent.Enabled = true;
                    int index = dataBoundItem.ItemIndex;
                    chkBoxParent.Attributes.Add("onclick", "check('" + index + "')");
     
                }
            }

    function check(index) {
        var grid = $find("<%= RadGrid1.ClientID %>");
                    var MasterTable = grid.get_masterTableView();
                    var row = MasterTable.get_dataItems()[index];
                    var cell = MasterTable.getCellByColumnUniqueName(row, "Parent");
                    if (cell.innerHTML == "True") {
                        alert('TRUE');
                    }
                }



    But cell.innerHTML return something like this:

    <INPUT id=ctl00_ContentPlaceHolder1_RadGrid1_ctl00_ctl08_ctl00 onclick="check('2');" type=checkbox name=ctl00$ContentPlaceHolder1$RadGrid1$ctl00$ctl08$ctl00>
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 28 Jun 2013 Link to this post

    Hello,

    function check(index) {
                    var grid = $find("<%= RadGrid1.ClientID %>");
                    var MasterTable = grid.get_masterTableView();
                    var row = MasterTable.get_dataItems()[index];
                    var cell = MasterTable.getCellByColumnUniqueName(row, "Parent");
                    if ($(cell).find('input').is(":checked") == true) {
                        alert('TRUE');
                    }
                }

    OR

    if (cell.getElementsByTagName('input')[0].checked == true) {


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Peter
    Peter avatar
    98 posts
    Member since:
    Mar 2012

    Posted 22 Oct 2014 in reply to Jayesh Goyani Link to this post

    How do I access an unbound checkbox value in the Grid's UpdateCommand event? 

    When I use the "ExtractValuesFromItem" method, the item has a blank name in hashtable. 
  5. Peter
    Peter avatar
    98 posts
    Member since:
    Mar 2012

    Posted 22 Oct 2014 in reply to Peter Link to this post

    I worked it out:

    protected void rgGrid_UpdateCommand(object sender, GridCommandEventArgs e)
            {
                GridEditableItem editItem = e.Item as GridEditableItem;
                _isIgnore = ((CheckBox)((GridEditableItem)e.Item)["chkIgnore"].Controls[0]).Checked;
Back to Top