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

GridTemplateColumn + Aggregate Property

9 Answers 618 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gino Suarez
Top achievements
Rank 1
Gino Suarez asked on 22 Oct 2009, 04:09 PM
Hi, i'm trying to simulate the action of use aggregate="sum" property for a telerik:gridtemplatecolumn i use this kind of column `cause i need to set links in each cell value , when i use telerik:gridboundcolumn i cant use <item template><asp_hyperlink>, so finally what i need is set groupfooter totals, footer total and set as hyperlinks in each cell value. actually i can set the footer totals and the links but i cant set the group footer totals tnaks a lot and sorry for my english

<telerik:GridTemplateColumn UniqueName="Template1" GroupByExpression = "Febrero"
                                                 
                                                    <ItemTemplate>                                                         
                                                        <asp:HyperLink ID="targetControl" runat="server" NavigateUrl="#" Text='<%# Eval("Febrero") %>'></asp:HyperLink> 
                                                    </ItemTemplate>               
                                                    <FooterTemplate>                                                         
                                                        <asp:HyperLink runat="server" ID="TextBox2"
                                                        </asp:HyperLink>                                                         
                                                    <telerik:GridGroupPanel> 
                                                    <PanelItemsStyle Height="200" BackColor="Aquamarine" /> 
                                                    </telerik:GridGroupPanel> 
                                                    </FooterTemplate>    
                                                                                                                                                          
                                                </telerik:GridTemplateColumn> 
 
protected void tk_Grid_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            sum += double.Parse((dataItem["Template1"].FindControl("targetControl") as HyperLink).Text); 
        } 
        else if (e.Item is GridFooterItem) 
        { 
            GridFooterItem footer = (GridFooterItem)e.Item; 
            (footer["Template1"].FindControl("TextBox2") as HyperLink).Text = sum.ToString(); 
            FooterTotals = (footer["Template1"].FindControl("TextBox2") as HyperLink).Text; 
        } 

9 Answers, 1 is accepted

Sort by
0
Accepted
Sebastian
Telerik team
answered on 27 Oct 2009, 03:47 PM
Hello Gino,

Your implemenation seems correct. Can you please verify (debugging your code) that the logic in the ItemDataBound handler gets executed as expected. Additionally, confirm that the sum variable has global scope in the code behind as in the corresponding paragraph of this help topic.

You may also be happy to know that we will introduce declarative aggregates for GridTemplateColumns (by their DataField property setting) with the Q3 2009 release of RadGrid, expected next week.

Best regards,
Sebastian
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
Gino Suarez
Top achievements
Rank 1
answered on 27 Oct 2009, 05:06 PM
Hello Sebastian,

finally i can fix it, the only i need to put groupfootertotals and switch each value into hyperlinks is:
 else if (e.Item is GridGroupFooterItem)        {           
            GridGroupFooterItem gridfooteritem = e.Item as GridGroupFooterItem;

            gridfooteritem["Apertura"].Text = "<a class=links href=" + sumape.ToString() + ">" + sumape.ToString() + "</a>";
 

then when i need to call a popup window i can't doit from an asp:hyperlink so i set asp:hyperlink visible = false (just use it for the itemdatabound event) and put an <a href.... filled with the same data , what do you think ? thanks Sebastian and all the telerik team for your efforts, this is a great components suite and im waiting for Q3.

<telerik:GridTemplateColumn UniqueName="Enero" ItemStyle-HorizontalAlign="Right" HeaderText="Ene"
                            <HeaderTemplate> 
                           <href="#" onclick="AbreVentana('frmEEFFMensual.aspx?Periodo=ENERO&MesID=1','Balance');">Ene</a> 
                            </HeaderTemplate> 
                           <HeaderStyle HorizontalAlign="Right" /> 
                           <ItemTemplate> 
                         <href="#" class="links" onclick="AbreVentana('frmAnexoBalance.aspx?Periodo=ENERO&MesID=1','Balance');"><%# Eval("Enero") %></a
                       <asp:HyperLink ID="lnkEnero" Visible="false" CssClass="links" Target="_blank" runat="server" NavigateUrl="frmAnexoBalance.aspx?Periodo=ENERO&MesID=1" Text='<%# Eval("Enero") %>'></asp:HyperLink> 
                                                    </ItemTemplate>  
                                                    <FooterStyle HorizontalAlign="Right" />              
                                                    <FooterTemplate>                                                         
                                                        <asp:HyperLink runat="server" ID="SumEnero" NavigateUrl="#" Text="" CssClass="linkstotal"
                                                        </asp:HyperLink>                                                         
                                                    </FooterTemplate>                                                                                                                                                             
                                                </telerik:GridTemplateColumn> 

Best Regards

Gino


0
Amanda
Top achievements
Rank 1
answered on 08 Nov 2010, 11:54 PM
Is there a way to do this in javascript?
0
Sebastian
Telerik team
answered on 09 Nov 2010, 10:57 AM
Hi Amanda,

Consider the javascript solution presented on this integration example:
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandinput/defaultcs.aspx?product=grid

Examine the description and code snippets for more info.

Best,
Sebastian
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
Amanda
Top achievements
Rank 1
answered on 09 Nov 2010, 03:48 PM
Sebastian, thank you for the reply - but that doesn't seem to work for me - can you tell me what I am doing wrong?  When I run this the requestedTotal and the Variance get the same output - and it is not updating when I update. 
Here is the javascript:
function Variance(sender, args)
    {
        var rdgrid = $find("<%=RadGrid1.ClientID %>");
        var cell = sender.get_element().parentNode.parentNode;
        var index = cell.parentNode.rowIndex;
        var MasterTable = rdgrid.get_masterTableView();
        var row = MasterTable.get_dataItems()[index - 2]; //getting row
        var tbxAdopted = row.findControl("tbxAdopted").get_value(); //getting value of TextBox 'tbxAdopted'
        var tbxReq = row.findControl("tbxReq").get_value();
        var Variance = tbxReq - tbxAdopted;
        var tbxVariance = MasterTable.get_dataItems()[index - 2].findControl("tbxVar");
        tbxVariance.set_value(Variance);
    }

function RequestedTotal(sender) {
        sumInput = sender;
        tempValue = sumInput.get_value() - sender.get_value();
        sumInput.set_value(tempValue + sender.get_value());
    }

    function VarianceTotal(sender, args) {
        sumInput = sender;
        tempValue = sumInput.get_value() - sender.get_value();
        sumInput.set_value(tempValue + sender.get_value());

    }

Here is my radGrid:
'Format Code Block'
<telerik:RadGrid ID="RadGrid1" runat="server" ShowFooter="true" AutoGenerateColumns="False"
                    AllowSorting="true" EnableEmbeddedSkins="False" Skin="GridCustom" Width="1000px"
                    EnableLinqExpressions="false" OnItemDataBound="RadGrid1_ItemDataBound" OnNeedDataSource="RadGrid1_NeedDataSource1"
                    OnItemCreated="RadGrid1_ItemCreated" OnUpdateCommand="RadGrid1_UpdateCommand"
                    OnItemCommand="RadGrid1_ItemCommand" OnColumnCreated="RadGrid1_ColumnCreated"
                    OnInsertCommand="RadGrid1_InsertCommand" OnCancelCommand="RadGrid1_CancelCommand"
                    OnPreRender="RadGrid1_PreRender">
                    <MasterTableView DataKeyNames="Account" EditMode="InPlace" CommandItemDisplay="TopAndBottom"
                        InsertItemDisplay="Top" AllowAutomaticInserts="false" ShowGroupFooter="true">
                        <Columns>
                            <telerik:GridEditCommandColumn ButtonType="PushButton" Visible="false">
                                <ItemStyle HorizontalAlign="Center" Width="100px" CssClass="BorderLeft BorderRight BorderBottom" />
                                <FooterStyle CssClass="BorderLeft BorderRight BorderBottom" />
                            </telerik:GridEditCommandColumn>
                            <telerik:GridTemplateColumn DataField="LongAccount" HeaderStyle-HorizontalAlign="Center"
                                UniqueName="LongAccount" HeaderText="Account" ReadOnly="true" ShowSortIcon="false"
                                FooterText="Sub Total">
                                <ItemTemplate>
                                    <asp:Label ID="lblAccount" runat="server" Text='<%#Bind("LongAccount") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <div style="width: 120px;">
                                    </div>
                                    <table cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td style="width: 120px; padding-left: 0;">
                                                <telerik:RadMaskedTextBox ID="mtbxAccount" runat="server" Text='<%# Bind("Account")%>'  >
                                                <ClientEvents OnValueChanged="onChange" />
                                                </telerik:RadMaskedTextBox>
                                            </td>
                                            <td style="font-size: small; padding-left: 5px;">
                                                <input id="Button1" type="button" value="Available Accounts" onclick="openWin(); return false;" />
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="mtbxAccount"
                                                    ErrorMessage="Required" runat="server">
                                                </asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                    </table>
                                </EditItemTemplate>
                                <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                <ItemStyle HorizontalAlign="Left" Width="100px" CssClass="BorderRight BorderLeft BorderBottom" />
                                <FooterStyle CssClass="BorderRight BorderLeft BorderBottom" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField="Description" ReadOnly="true" UniqueName="Description"
                                HeaderText="Description" ShowSortIcon="false">
                                <ItemStyle HorizontalAlign="Left" Width="200px" CssClass="BorderRight BorderBottom" />
                                <FooterStyle CssClass="BorderRight BorderBottom" />
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn DataField="Adopted" ReadOnly="true" HeaderStyle-HorizontalAlign="Center"
                                UniqueName="Adopted" HeaderText="Adopted" ShowSortIcon="false" >
                                <ItemTemplate>
                                    <telerik:RadNumericTextBox ID="tbxAdopted" Value='<%#Bind("Adopted") %>' CssClass="RightAlign" ReadOnly="true"
                                        runat="server" Culture="English (United States)" Type="Number" NumberFormat-DecimalDigits="0"
                                        Width="90px" MinValue="-999999" DataType="System.Int32" Enabled="false" DataFormatString="{0:N0}">
                                    </telerik:RadNumericTextBox>
                                </ItemTemplate>
                                <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                <ItemStyle HorizontalAlign="Right" Width="100px" CssClass="BorderRight BorderBottom" />
                                <FooterStyle CssClass="BorderRight BorderBottom" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="Requested" ReadOnly="true" HeaderStyle-HorizontalAlign="Center"
                                UniqueName="Requested" HeaderText="Requested" ShowSortIcon="false">
                                <EditItemTemplate>
                                    <telerik:RadNumericTextBox ID="tbxRequested"  DbValue='<%#Bind("Requested") %>' runat="server"
                                        Culture="English (United States)" Type="Number"  NumberFormat-DecimalDigits="0"
                                        Width="90px" MinValue="0" DataType="System.Int32" >
                                    </telerik:RadNumericTextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <telerik:RadNumericTextBox ID="tbxReq" Value='<%#Bind("Requested") %>' CssClass="RightAlign"
                                        runat="server" Culture="English (United States)" Type="Number" NumberFormat-DecimalDigits="0"
                                        Width="90px" MinValue="0" DataType="System.Int32" Enabled="false">
                                        <ClientEvents OnValueChanged="Variance" />
                                    </telerik:RadNumericTextBox>
                                </ItemTemplate>
<%--                                <FooterTemplate>
                                    <telerik:RadNumericTextBox ID="tbxVarRequested" runat="server" Type="Currency" ReadOnly="true" DataFormatString="{0:N0}">
                                    <ClientEvents OnLoad="RequestedTotal" />
                                    </telerik:RadNumericTextBox>
                                </FooterTemplate>--%>
                                <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                <ItemStyle HorizontalAlign="Right" Width="100px" CssClass="BorderRight BorderBottom" />
                                <FooterStyle CssClass="BorderRight BorderBottom" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="Variance" ReadOnly="true" HeaderStyle-HorizontalAlign="Center"
                                UniqueName="Variance" HeaderText="Variance" ShowSortIcon="false" >
                                <ItemTemplate>
                                    <telerik:RadNumericTextBox ID="tbxVar" Value='<%#Bind("Variance") %>' CssClass="RightAlign"  ReadOnly="true"
                                        runat="server" Culture="English (United States)" Type="Number" NumberFormat-DecimalDigits="0"
                                        Width="90px" MinValue="-999999" DataType="System.Int32" Enabled="false" DataFormatString="{0:N0}">
                                         <ClientEvents OnValueChanged="VarianceTotal" />

                                    </telerik:RadNumericTextBox>
                                </ItemTemplate>
<%--                                <FooterTemplate>
                                    <telerik:RadNumericTextBox ID="tbxVarFooter" runat="server" Type="Currency" ReadOnly="true" DataFormatString="{0:N0}">
                                    <ClientEvents OnLoad="VarianceTotal" />
                                    </telerik:RadNumericTextBox>
                                </FooterTemplate>--%>
                                <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                <ItemStyle HorizontalAlign="Right" Width="100px" CssClass="BorderRight BorderBottom" />
                                <FooterStyle CssClass="BorderRight BorderBottom" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField="AcctType" Visible="false" ReadOnly="true" UniqueName="AcctType"
                                HeaderText="AcctType" ShowSortIcon="false">
                                <ItemStyle HorizontalAlign="Left" CssClass="BorderRight BorderBottom" />
                                <FooterStyle CssClass="BorderRight BorderBottom" />
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn DataField="Justification" UniqueName="Justification"
                                HeaderText="Justification" ShowSortIcon="false">
                                <EditItemTemplate>
                                    <table cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td>
                                                <asp:TextBox ID="txtJustification" Text='<%#Bind("Justification") %>' runat="server"
                                                    Width="500px" TextMode="MultiLine" Rows="4" MaxLength="2000">
                                                </asp:TextBox>
                                            </td>
                                            <td style="font-size: small; padding-left: 5px;">
                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Maximum 800 characters"
                                                    ControlToValidate="txtJustification" EnableTheming="True" ValidationExpression="^[\s\S]{0,800}$"></asp:RegularExpressionValidator>
                                                <asp:BulletedList ID="blistErrors" runat="server" ForeColor="Red" BulletStyle="Disc">
                                                </asp:BulletedList>
                                            </td>
                                        </tr>
                                    </table>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:TextBox ID="tbxJust" runat="server" TextMode="MultiLine" Rows="4" Width="360px"
                                        MaxLength="2000" Text='<%#Bind("Justification") %>'></asp:TextBox>
                                    <br />
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="Maximum 800 characters"
                                        ControlToValidate="tbxJust" EnableTheming="True" ValidationExpression="^[\s\S]{0,800}$"></asp:RegularExpressionValidator>
                                    <%--<asp:Label ID="lblJustification" runat="server" Text='<%#(Eval("Justification") == null || Eval("Justification") == "") ?"&nbsp":Eval("Justification") %>'></asp:Label>--%>
                                </ItemTemplate>
                                <HeaderStyle HorizontalAlign="Center" />
                                <ItemStyle CssClass="BorderRight BorderBottom" />
                                <FooterStyle CssClass="BorderRight BorderBottom" />
                            </telerik:GridTemplateColumn>
                        </Columns>
                        <EditFormSettings>
                            <FormTableItemStyle Wrap="false" Font-Bold="true" Font-Size="Small" />
                            <FormTableAlternatingItemStyle Wrap="false" Font-Bold="true" Font-Size="Small" />
                            <EditColumn ButtonType="PushButton" InsertText="Save" UpdateText="Save">
                            </EditColumn>
                            <FormMainTableStyle Width="1200px" />
                            <FormStyle BorderColor="Peru" BorderWidth="1px" BorderStyle="Solid" />
                            <FormTableButtonRowStyle HorizontalAlign="Center" Width="100%" />
                        </EditFormSettings>
                        <CommandItemTemplate>
                            <div style="margin: 2px 0 0 0; vertical-align: middle; text-align: left;">
                                <asp:Button ID="btnAddNew" runat="server" Text="Add New" Width="100px" CommandName="InitInsert" />
                                <asp:Button ID="btnSaveAll" runat="server" Text="Save All" Width="100px" CommandName="SaveAll" OnClientClick="return confirm('Please do not click the back button or navigate away from page until save is complete.');" />
                                <telerik:RadSpell ID="RadSpell1" runat="server" CssClass="RadSpellInline" Width="100px" AllowAddCustom="false" />
                                <asp:Button ID = "btnClear" runat ="server" Text="Clear" Width ="100px" CommandName="Clear" />
                            </div>
                        </CommandItemTemplate>
                    </MasterTableView>
                    <FilterMenu EnableEmbeddedSkins="False">
                    </FilterMenu>
                </telerik:RadGrid>

Code behind c#:
else if (e.Item is GridFooterItem)
        {
            GridFooterItem item = (GridFooterItem)e.Item;
            if (item != null)
            {
                //(item["Requested"].FindControl("tbxReqFooter") as RadNumericTextBox).Value = Double.Parse(_requestedTotal.ToString("N0"));
                item["Requested"].Text = _requestedTotal.ToString("N0");
                //(item["Variance"].FindControl("tbxVarFooter") as RadNumericTextBox).Value = Double.Parse(_requestedTotal.ToString("N0"));
                item["Variance"].Text = _varianceTotal.ToString("N0");
                item["Adopted"].Text = _adoptedTotal.ToString("N0");
                if (Denton.Service.MoneyToDouble(item["Variance"].Text) > 0)
                {
                    item["Variance"].ForeColor = System.Drawing.Color.Red;
                }
            }
        }
    }
0
Sebastian
Telerik team
answered on 12 Nov 2010, 12:30 PM
Hello Amanda,

I suggest you debug your javascript code to see whether the values are calculated accurately and set in the numeric textbox fields as expected. Also consider using your local version of the online demo as basis - its default installation location should be as follows:

C:\Program Files\Telerik\RadControls for ASP.NET AJAX QX 2010\Live Demos\Controls\Examples\Integration\GridAndInput (32 bit machine)

C:\Program Files (x86)\Telerik\RadControls for ASP.NET AJAX QX 2010\Live Demos\Controls\Examples\Integration\GridAndInput (64 bit machine)

Regards,
Sebastian
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
siva
Top achievements
Rank 1
answered on 05 Jan 2011, 03:25 PM

 

<telerik:RadGrid ID="RadGridClientMandate" GridLines="None" runat="server" AutoGenerateColumns="False"

 

 

 

 

 

OnItemDataBound="drmandates_ItemDataBound" Skin="3iGrid" EnableEmbeddedSkins="false"

 

 

 

 

 

Height="390px" Width="99.5%">

 

 

 

 

 

<MasterTableView InsertItemDisplay="Bottom" Width="100%" DataKeyNames="Security"

 

 

 

 

 

Visible="true">

 

 

 

 

 

<RowIndicatorColumn>

 

 

 

 

 

<HeaderStyle Width="20px" />

 

 

 

 

 

</RowIndicatorColumn>

 

 

 

 

 

<ExpandCollapseColumn>

 

 

 

 

 

<HeaderStyle Width="20px" />

 

 

 

 

 

</ExpandCollapseColumn>

 

 

 

 

 

<Columns>

 

 

 

<

 

telerik:GridTemplateColumn HeaderText="Order Value" ItemStyle-Width="99px" ItemStyle-HorizontalAlign="Right" UniqueName="Order Value" >

 

 

<ItemTemplate>

 

 

<asp:Label ID="OrderValue" runat="server" Text='<%# Bind("OrderValue") %>' />

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

am using above structure grid ,plz help me in setting number format comma seperation in asp:label

 

0
Princy
Top achievements
Rank 2
answered on 06 Jan 2011, 08:15 AM
Hello Siva,

Try the following approach to set format for text in Label control.

ASPX:
<telerik:GridTemplateColumn HeaderText="Order Value" ItemStyle-Width="99px" ItemStyle-HorizontalAlign="Right"
    UniqueName="Order Value">
   <ItemTemplate>
        <asp:Label ID="OrderValue" runat="server" Text=' <%# string.Format("{0:n}", Convert.ToInt64(Eval("OrderValue"))) %> ' />
   </ItemTemplate>
 </telerik:GridTemplateColumn>

You can also try it from code behind like below.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            Label lb = (Label)item.FindControl("OrderValue");
            Int64 value = Convert.ToInt64(lb.Text);
            lb.Text= String.Format("{0:n}", value);
        }
    }

Thanks,
Princy.
0
siva
Top achievements
Rank 1
answered on 09 Feb 2011, 01:59 PM
Hi Princy, 
 
i tried to use it bth are working fine

but the value is comming as ex:- 699,461,112,789.432
if i want to bring the comma seperation in  indian format  69,94,61,12,789.432 separated by 2 digits   how to achieve it
i tried the below code yet its not resolved,


 

<telerik:GridTemplateColumn HeaderText="Deficiency" ItemStyle-Width="99px" ItemStyle-HorizontalAlign="Right" UniqueName="DEFICIENCY">
<ItemTemplate>
<asp:Label ID="DEFICIENCY" runat="server" Text='<%# string.Format("{0:##,##,###,##,##,##,###.##}", Convert.ToDouble(Eval("DEFICIENCY"))) %>'>
</asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>

 

please  help me out in this respect

Thanks regards,
Siva.

Tags
Grid
Asked by
Gino Suarez
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Gino Suarez
Top achievements
Rank 1
Amanda
Top achievements
Rank 1
siva
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or