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

[Solved] Binding integer to checkbox in AutoGeneratedColumns and enable checkbox for edit

5 Answers 377 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DEV
Top achievements
Rank 1
DEV asked on 07 Mar 2014, 09:35 PM
I am using AutoGeneratedColumns for checkbox but I can only use integer for datasource. help me to find right way to convert int value(as 1 or 0) to checkbox column and also how to enable that  AutoGenerated checkbox column.

5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 12 Mar 2014, 06:37 PM
Hi,

When you set the AutoGenerateColumns property of RadGrid to true, the RadGrid control generates a separate column for each data field in the control's assigned datasource. Based on the DataType of the field, the grid control will generate the respective column types :
  • GridBoundColumn for string fields
  • GridCheckBoxColumn for boolean fields
  • GridDateTimeColumn for datetime fields
  • GridNumericColumn for numeric fields

GridCheckBoxColumn displays a check box to represent a Boolean value. You should bind this column type to a Boolean field by setting its DataField property. If this column type is bound to a data value that is not Boolean, the grid throws an exception.

Therefore, after you have auto generated columns, I would suggest you change your datasource to output a boolean value rather than an integer. The RadGrid will automatically pick this up and enable checkbox for edit.

Regards,
Pavlina
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
0
DEV
Top achievements
Rank 1
answered on 14 Mar 2014, 09:25 PM
Thanks for the reply. 

I already converted my datasource to Boolean but now I have another issue. I want to select/deselect checkbox from those Autogeneratedcolumns but those are disabled by default. Please tell me the right way to enable Autogenerated checkbox.
0
Shinu
Top achievements
Rank 2
answered on 17 Mar 2014, 06:36 AM
Hi Dev,

It is the default behavior of the GridCheckBoxColumn. When the grid is in browser mode, or if the column is read-only, the check box is disabled. When the column is editable, the check box is enabled. Check out the following document to understand better about the various columns supported by RadGrid.
Column types.

Thanks,
Shinu
0
DEV
Top achievements
Rank 1
answered on 17 Mar 2014, 04:03 PM
Thanks for the reply.

Should I use ItemDataBound or ItemCreated event to enable editmode of AutoGenerated GridCheckBox ?

Can you help me with sample code?
0
Shinu
Top achievements
Rank 2
answered on 18 Mar 2014, 04:09 AM
Hi Dev,

I guess you want to have the Grid in edit mode. You can set  the AutoGenerateEditColumn property of the RadGrid to true.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateEditColumn="true">

Please try and let me know if any concern.
Thanks,
Shinu
Tags
Grid
Asked by
DEV
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
DEV
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or