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

telerik:GridCheckBoxColumn editable?

7 Answers 1288 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Henry
Top achievements
Rank 1
Henry asked on 22 Jul 2015, 03:55 PM

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.

7 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 22 Jul 2015, 04:40 PM

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

0
Henry
Top achievements
Rank 1
answered on 22 Jul 2015, 06:43 PM

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

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

0
Konstantin Dikov
Telerik team
answered on 27 Jul 2015, 06:36 AM
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
0
Henry
Top achievements
Rank 1
answered on 09 Sep 2015, 06:35 PM

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>

​

​

0
Konstantin Dikov
Telerik team
answered on 10 Sep 2015, 02:27 PM
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
0
Rob Ainscough
Top achievements
Rank 1
answered on 25 Sep 2018, 04:51 PM

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.

0
Tsvetomir
Telerik team
answered on 26 Sep 2018, 11:20 AM
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.
Tags
Grid
Asked by
Henry
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Henry
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Rob Ainscough
Top achievements
Rank 1
Tsvetomir
Telerik team
Share this question
or