Conditional Logic in Custom Template column

9 posts, 0 answers
  1. Jack
    Jack avatar
    45 posts
    Member since:
    Feb 2009

    Posted 27 Jan 2009 Link to this post

    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

       if dataType = 'Number' then 'bind to dropdown list'
       if dataType = 'date' then 'bind to calendar'

    Any thoughts?



  2. Pavel Pavlov
    Pavel Pavlov avatar
    2039 posts

    Posted 02 Feb 2009 Link to this post

    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.

    Pavel Pavlov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. DevCraft R3 2016 release webinar banner
  4. Nikhil
    Nikhil avatar
    23 posts
    Member since:
    May 2009

    Posted 01 Jun 2009 Link to this post

  5. Dhileep Kumar Sampath
    Dhileep Kumar Sampath avatar
    35 posts
    Member since:
    Oct 2009

    Posted 31 Oct 2009 Link to this post

    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?

  6. Vlad
    Vlad avatar
    11100 posts

    Posted 03 Nov 2009 Link to this post

    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,
    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.
  7. Benedict
    Benedict avatar
    16 posts
    Member since:
    Jun 2009

    Posted 16 Mar 2010 Link to this post


    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 ?
  8. Vlad
    Vlad avatar
    11100 posts

    Posted 16 Mar 2010 Link to this post

    Hi Benedict,

    Currently we don't have template selectors and the easiest way to achieve your goal is demonstrated on this blog post:

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

    All the best,
    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.
  9. Joel Palmer
    Joel Palmer avatar
    164 posts
    Member since:
    May 2009

    Posted 10 Mar 2014 in reply to Vlad Link to this post

    The link in the prior post is invalid.
  10. Maya
    Maya avatar
    4062 posts

    Posted 11 Mar 2014 Link to this post

    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.


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

Back to Top
DevCraft R3 2016 release webinar banner