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

Conditional Logic in Custom Template column

8 Answers 290 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jack
Top achievements
Rank 1
Jack asked on 27 Jan 2009, 05:25 PM
With regards to the CustomTemplate Blog that was posted yesterday I was wondering if it is possible to manage conditional conditions.

I have a generic data entry window where the user needs to enter different types of data but into the same businessObject property.  The business object then handles the logic of assigning it to a number, date, string, etc.  The binding property DataValue is of type Object.

In previous implementations (PowerBuilder) I basically had a grid but where I wanted to capture my data I had a dateField, a textField, a numberField and I stacked them on top of each other and then did a hide/show to let the user use the appropriate control.

My ultimate goal is to provide a rich set of input controls depending on the data type and the column type.  So date would have a calendar, number could be a masked input, a checkbox, a dropdown list of values, a radio button set, a spinner control etc. 

I also need to show a bunch of icons that indicate status, validity, etc.  All these are bindable properties of my BusinessObject.

My original plan was to create a base usercontrol and then inherit from it for each input type I needed.  Then I would create a giant stackpanel and add the user controls to it.  That simulates my one data value per row concept.

When I saw the blog posting I thought maybe I could do it in a grid.  The grid would obviously give me all the extra grid benefits (filtering is the key one) for free.

So is there a recommended solution for this type of implementation?  Do I go ahead with my user controls and then is there a way to put them into the template column and somehow pass all the data binding through to the control?

or can I do something in the template columns based on the conditions of my dataType/FieldType

ie)
<TemplateColumm>
...
   if dataType = 'Number' then 'bind to dropdown list'
   if dataType = 'date' then 'bind to calendar'
...

Any thoughts?

thanks

jack


8 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 02 Feb 2009, 09:07 AM
Hello Jack,

Normally the RadGridView relies on its own GridViewCellEditor for editing  the cell's value.
You can, however, set a cell template to a column containing your custom user control for editing different data-types.
This user control should handle the editing logic and should take care after editing is ended to update the parent cell's Value property (via binding or code). You can either bind to the Value property of the parent cell or change it in the code-behind of your user control.

Filtering is one of the many benefits you get from the RadGridView. However, be aware that filtering can be tricky on such a column containing different types boxed in an object type.

If you intend to filter other "stronger typed" columns , this approach would be OK .

Further  if you need any collaboration on your scenario let us know ( with some more details about the specific case) so we can prepare some samples for you and the community.


Regards,
Pavel Pavlov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Nikhil
Top achievements
Rank 1
answered on 01 Jun 2009, 05:10 AM
do
0
Dhileep Kumar Sampath
Top achievements
Rank 1
answered on 31 Oct 2009, 11:01 AM
Hi Telerik Team,
             I need to add the columns dynamically in my grid and my first row contains checkboxes in all the columns and other rows contains string. I see that above scenario suits this case. Can you guys please let me know how to bind two different datatypes in a column using templates (conditionally).

Is there a templateselector similar to ItemTemplateSelector in treeview?

Thanks,
Dhileep
0
Vlad
Telerik team
answered on 03 Nov 2009, 06:40 AM
Hi Dhileep,

The easiest way is to create your own column, inhering from GridViewDataColumn, override CreateCellEditElement and return desired control depending on your condition.

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Benedict
Top achievements
Rank 1
answered on 16 Mar 2010, 08:29 AM
Hello,

I would need a cell template selector too. I have an XML-Structure in one Datafield and I want to Format Contend depending on the XML-Content. Our do I have any other oportunities ?
0
Vlad
Telerik team
answered on 16 Mar 2010, 08:44 AM
Hi Benedict,

Currently we don't have template selectors and the easiest way to achieve your goal is demonstrated on this blog post:
http://blogs.telerik.com/pavelpavlov/posts/09-10-03/adding_additional_power_to_radgridview_for_silverlight_with_attached_behaviors.aspx

We will do our best to add template selectors for Q2 2010 (beta middle of June)

All the best,
Vlad
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
Joel Palmer
Top achievements
Rank 2
answered on 11 Mar 2014, 02:37 AM
The link in the prior post is invalid.
0
Maya
Telerik team
answered on 11 Mar 2014, 07:50 AM
Hello Joel,

The link to the blog post is "Adding additional power to RadGridView for Silverlight with attached behaviors".
However, RadGridView has had a support for template selectors for quite some time now. Please take a look at our documentation and demos for a reference:
1. CellTemplateSelector demo
2. CellTemplateSelector documentation.



Regards,
Maya
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.

Tags
GridView
Asked by
Jack
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Nikhil
Top achievements
Rank 1
Dhileep Kumar Sampath
Top achievements
Rank 1
Vlad
Telerik team
Benedict
Top achievements
Rank 1
Joel Palmer
Top achievements
Rank 2
Maya
Telerik team
Share this question
or