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
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
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?
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.
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?
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.
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); |
|
} } |
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.
Hello Nikolay,
Thanks a lot for supporting, and for forwarding my small points of view to developers. In generall, Telerik produce very good components!!!
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.