Show Text Field in Place of Numeric

6 posts, 1 answers
  1. Neil N
    Neil N avatar
    75 posts
    Member since:
    Aug 2012

    Posted 20 Mar 2013 Link to this post

    Example dataset:

    Company Material Collected
    A Stone 1
    A Wood 0
    A Marble 1
    A Plastic 1
    B Stone 0
    B Wood 0
    B Marble 0
    B Plastic 1
    C Stone 1
    C Wood 1
    C Marble 1
    C Plastic 1

    Is it possible to show "Yes" for 1 and "No" for 0 while still retaining aggregate functionality?  Basically, the aggregate should be a sum which is a count of "Yes".
  2. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 25 Mar 2013 Link to this post

    Hello Neil,

    A possible approach is shown below:
    <telerik:RadGrid ID="RadGrid1" runat="server" ShowFooter="true">
        <MasterTableView>
            <Columns>
                <telerik:GridTemplateColumn DataField="Bfield" HeaderText="Bfield" UniqueName="Bfield"
                    Aggregate="Count">
                    <ItemTemplate>
                        <%# ((bool)Eval("Bfield")) ? "Yes" : "No"  %>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    Let me know whether this way is suitable for you.

    Regards,
    Daniel
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Neil N
    Neil N avatar
    75 posts
    Member since:
    Aug 2012

    Posted 27 Mar 2013 Link to this post

    This is the PivotGrid forum. I'm using a PivotGrid.
  5. Answer
    Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 01 Apr 2013 Link to this post

    Hello Neil,

    Excuse me for this omission. Working with RadPivotGrid templates is quite similar to RadGrid and the other databound controls. The only difference is that you don't have to use Eval. Just write Container.DataItem and then cast the result to the underlying type.
    <telerik:PivotGridAggregateField DataField="YourDataField">
        <CellTemplate>
            <%# (YourType)Container.DataItem == 0 ? "Yes" : "No"  %>
        </CellTemplate>
    </telerik:PivotGridAggregateField>

    I doubt however, that the aggregated data will return only 1 and 0 as there are not many cases (for example you can have bit field with min/max aggregate) where this would happen.

    Best regards,
    Daniel
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Neil N
    Neil N avatar
    75 posts
    Member since:
    Aug 2012

    Posted 01 Apr 2013 Link to this post

    Thanks, adapting your example to VB.NET works great.
    <CellTemplate><%# IIf(CBool(Container.DataItem), "Yes", "No")%></CellTemplate>
  7. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 02 Apr 2013 Link to this post

    Hello Neil,

    I'm glad to hear that you have managed to achieve this functionality. You may also want to examine our online resources:
    How to Customize Telerik's ASP.NET PivotGrid Cells Using the Built-in Templates blog post
    PivotGrid Templates documentation
    PivotGrid Templates example

    Best regards,
    Daniel
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017