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

[Solved] GridCheckboxColumn - How to Bind NUMBER 0 and 1 value?

11 Answers 730 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Maxim Tairov
Top achievements
Rank 1
Maxim Tairov asked on 12 May 2009, 01:33 PM

Hello Telerik, 

I have problem when I try to assign GridCheckbox column with Number datatype column (real value 0 and 1 in datasource table). I have saw Exception in Internal method GridCheckBoxColumn.OnDataBindColumn. Is it possible to work with number field as boolean in GridCheckBoxColumn.

11 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 May 2009, 04:56 AM
Hi Maxim,

GridCheckBoxColumn will accept only boolean value. But you can achieve the desired scenario using a GridTemplateColumn with a CheckBox in its ItemTemplate. Give a try with the following approach and whether it is working.

ASPX:
 
  <telerik:GridTemplateColumn UniqueName="CheckCol" DataField="TestField" HeaderText="CheckCol" > 
            <ItemTemplate> 
                <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# DataBinder.Eval (Container.DataItem,"TestField").ToString()!="0"?true:false %>' /> 
            </ItemTemplate> 
          </telerik:GridTemplateColumn> 


Regards
Shinu
0
Maxim Tairov
Top achievements
Rank 1
answered on 13 May 2009, 07:46 AM

Hello Shinu,

Thanks for your response, but my application build all columns in runtime. Possible there is a sample how to create GridTemplateColumn in runtime?

0
Sebastian
Telerik team
answered on 13 May 2009, 08:28 AM
Hello Maxim,

You can see how to instantiate grid template columns programmatically in the bottom section of this documentation article.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Maxim Tairov
Top achievements
Rank 1
answered on 13 May 2009, 09:17 AM

Hi Sebastian!

Interesting Articale, but Template column should be created BEFORE restoring from ViewState (In Page_Init handler only). My application can't do it all time. Column configuration changed AFTER Page_Init event. So Is it possible to override default binding for GridCheckboxColumn?

0
Sebastian
Telerik team
answered on 13 May 2009, 09:57 AM
Hello Maxim,

Unfortunately this is not possible and to keep the viewstate/lifecycle of the grid consistent when having programmatically created template columns, you need to build the control inside the OnInit handler.

An alternative solution for your case might be to determine the columns and their type based on the value from another control on the page as illustrated in this documentation topic.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Maxim Tairov
Top achievements
Rank 1
answered on 13 May 2009, 10:24 AM

Sebastian, I have found solution.

GridCheckboxColum is using private method  OnDataBindColumn for binding data into checkbox control. This method is  hooked  inside public method InitializeCell. So, in generall I can't make an access to binding method. I can't understand for why  binding method has a private attribute? Possible it is nessesary for some internal features of RadGrid architecture. But in generall I can't use GridCheckbox column if I am using Oracle database. So, please think about make binding method protected in future versions. 

Here is my solution of How to Bind 0 and 1 Number values into GridCheckBoxColumn

1. Create custom CustomGridCheckBoxColumn  which is iherrited from GridCheckBoxColumn

2. Create custom binding handler: OnDataBindColumnEx()

3. Override GridCheckBoxColumn.InitializeCell method:

 {

    base.InitializeCell(cell, columnIndex, inItem);        

    if (inItem.IsDataBound)  
    {  

       //Remove standard binding Handler

       EventInfo eventInfo = inItem.GetType().GetEvent("CellDataBound");  

       Type tDelegate = eventInfo.EventHandlerType;  
 
       MethodInfo dataBindBaseMehtod = GetType().BaseType.GetMethod  ("OnDataBindColumn", BindingFlags.NonPublic | BindingFlags.Instance);  
 
       Delegate d = Delegate.CreateDelegate(tDelegate, this, dataBindBaseMehtod);  
 
       eventInfo.RemoveEventHandler(inItem, d);  
       //Set new custom Handler  
       inItem.CellDataBound += new GridCellDataBoundEvent (this.OnDataBindColumnEx);  

     }

0
Nikolay Rusev
Telerik team
answered on 15 May 2009, 03:32 PM
Hello Maxim,

I have already forward your request to our developer for further consideration.
If they find it appropriate suggestion will be applied within one of the next release's.

Best wishes,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Maxim Tairov
Top achievements
Rank 1
answered on 18 May 2009, 08:07 AM

Hello Nikolay,

Thanks a lot for supporting, and for forwarding my small points of view to developers. In generall, Telerik produce very good components!!!

0
Bob Smith
Top achievements
Rank 1
answered on 26 Feb 2010, 02:20 PM
How would I do the reverse then - edit the record and take the checked property and turn it back into a bit to update the db?
0
Nikolay Rusev
Telerik team
answered on 03 Mar 2010, 05:06 PM
Hello Bob,

If you are not using automatic operations you will have to manually convert extracted values before perform actual db operations.

All the best,
Nikolay
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Bob Smith
Top achievements
Rank 1
answered on 03 Mar 2010, 05:58 PM
My apologies. I posted this before I even tried to use the field in a GridCheckboxColumn. I was pleased to discover that it works just fine for both display and editing.
Tags
Grid
Asked by
Maxim Tairov
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Maxim Tairov
Top achievements
Rank 1
Sebastian
Telerik team
Nikolay Rusev
Telerik team
Bob Smith
Top achievements
Rank 1
Share this question
or