telerik:GridCheckBoxColumn editable?

8 posts, 0 answers
  1. Henry
    Henry avatar
    42 posts
    Member since:
    Apr 2012

    Posted 22 Jul 2015 Link to this post

    In the radgrid, I have a boolean value binds to telerik:GridCheckBoxColumn.

    By default the checkbox is disabled. Is it possible to enable it in the grid browse mode (not in row edit mode), and allow postback when use check or uncheck the checkbox(so in the codebehind the value can be updated and saved to database)? 

    This is the document for gridcheckboxcolumn: http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/columns/column-types#gridcheckboxcolumn. 

    Thanks.

  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 22 Jul 2015 in reply to Henry Link to this post

    Hello,

    Please try with the below code snippet.

    <telerik:RadGrid ID="RadGrid1" runat="server">
        <MasterTableView DataKeyNames="ID">
            <Columns>
                <telerik:GridTemplateColumn UniqueName="ChkColumn">
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox CheckBox1 = sender as CheckBox;
        string strID = ((sender as CheckBox).NamingContainer as GridDataItem).GetDataKeyValue("ID").ToString();
        //Perform your DB operation
    }

     

    Please replace "ID" with your primary field name.

    Let me know if any concern.

    Thanks,

    Jayesh Goyani

  3. Henry
    Henry avatar
    42 posts
    Member since:
    Apr 2012

    Posted 22 Jul 2015 in reply to Jayesh Goyani Link to this post

    This is what I currently doing: have a regular checkbox inside of GridTemplateColumn.

     I was thinking that the telerik:GridCheckBoxColumn ​might be more convenient. 

  4. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2406 posts

    Posted 27 Jul 2015 Link to this post

    Hi Henry,

    The GridCheckBoxColumn does not support enabled checkbox control in the normal mode, because RadGrid does not support editors in the normal state and only in edit mode. Placing editors in the normal mode is not supported scenario that should be handled manually by the developer and using GridTemplateColumn is the only valid option.

    Hope this helps.


    Regards,
    Konstantin Dikov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Henry
    Henry avatar
    42 posts
    Member since:
    Apr 2012

    Posted 09 Sep 2015 Link to this post

    I had an issue of showing the loading image of another control when user click this checkbox. Below is the code, when the user click the checkbox, the loading image doesn't show on  RadGrid2. Can you help to check if anything wrong?  Thanks.

     

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
         <AjaxSettings>
    <telerik:AjaxSetting AjaxControlID="CheckBox1">
    <UpdatedControls>
    <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="rdPanel" />
    </UpdatedControls>
    </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

    <telerik:RadGrid ID="RadGrid1" runat="server">
        <MasterTableView DataKeyNames="ID">
            <Columns>
                <telerik:GridTemplateColumn UniqueName="ChkColumn">
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    <telerik:RadGrid ID="RadGrid2" runat="server">
    ...
    </telerik:RadGrid>

  6. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2406 posts

    Posted 10 Sep 2015 Link to this post

    Hello Henry,

    With controls nested in GridTemplateColumn you will not be able to include the ID of that controls in the way that you are trying to, because that control will not be in the same scope. For including the CheckBox control in the AJAX settings in this scenario you will have to use the approach demonstrated in the following help article and add the AJAX settings dynamically:
    However, please note that enabling AJAX for nested controls in the grid is not a recommended approach and I highly recommend that you enable the AJAX for the entire grid and add it to the AJAX settings instead of the "CheckBox1" that you currently have.

    Hope this helps.


    Regards,
    Konstantin Dikov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. Rob Ainscough
    Rob Ainscough avatar
    243 posts
    Member since:
    Jan 2010

    Posted 25 Sep 2018 in reply to Konstantin Dikov Link to this post

    I posted in another thread on a related topic.  Can someone tell me how I can have an "editable" checkbox that IS bound to the same datasource that populates the Grid?

    Cheers, Rob.

  8. Tsvetomir
    Admin
    Tsvetomir avatar
    147 posts

    Posted 26 Sep 2018 Link to this post

    Hi Rob,

    By design, it is expected the GridCheckBoxColumn to be read-only (disabled) in view mode. When the column is editable, the checkbox is enabled. The Grid - Column Types demo exposes the default behavior of the different column types, including the GridCheckBoxColumn.

    In order to have the checkbox enabled both - in view mode and in edit mode, you will have to use a TemplateColumn with a checkbox inside the ItemTemplate. The check state of the checkbox could be modified based on the data (in boolean type) coming from the data source of the grid, using the DataField property. 

    Another approach would be to set the check state of control in the ItemDataBound event handler of the grid which is fired after an item is databound to the RadGrid control. In the event handler, based on the value from the data source, you can either check or uncheck the checkbox. 

    Let me know if you need further clarifications or assistance.

    Kind regards,
    Tsvetomir
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top