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

Dyamic Footer Total Error

5 Answers 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prathibarani
Top achievements
Rank 1
Prathibarani asked on 18 Apr 2013, 07:14 PM
Hi,

We are using latest Radgrid in our asp.net application. I need to provide user a textbox to enter amounts into for each account. I need to show total amount entered by user for all accounts in footer. For this I am using template column with RadNumeric textbox like this:

<

 

 

telerik:GridTemplateColumn AllowFiltering="False" FilterControlAltText="Filter Amount column" Groupable="False" HeaderText="Amount" Reorderable="False" ShowFilterIcon="False" UniqueName="Amount" HeaderTooltip="Amount">

 

 

 

<HeaderStyle Width="17%"></HeaderStyle>

 

 

 

<ItemTemplate>

 

 

 

<telerik:RadNumericTextBox ID="txtAmount" runat="server"

 

 

 

Type="Currency" Width="75%" CssClass="rightalign">

 

 

 

<ClientEvents OnBlur="Blur" OnFocus="Focus" />

 

 

 

</telerik:RadNumericTextBox>

 

 

 

</ItemTemplate>

 

 

 

<FooterTemplate>

 

 

 

<asp:Literal ID="Literal1" runat="server" Text="Sum"></asp:Literal>

 

 

 

<telerik:RadNumericTextBox ID="txtAmountTotal" runat="server" Type="Currency">

 

 

 

<ClientEvents OnLoad="Load" />

 

 

 

</telerik:RadNumericTextBox>

 

 

 

</FooterTemplate>

 

 

 

</telerik:GridTemplateColumn>

 


As suggested in the link:
http://www.telerik.com/community/code-library/aspnet-ajax/general/refresh-footer-values-in-radgrid-client-side-using-radnumerictextbox.aspx

I have code in java script.
When I run my app and enter into textbox,

function

 

 

Focus(sender, args)

 

{

tempValue = sumInput.GetValue() - sender.GetValue();

}


gets called and I get an error on this line saying that 'Object doesn't support property or method 'GetValue''. I am not sure where it is going wrong.

I am not using 'NeedDataSourceEvent' because my application is complicated and we bind the grid when ever it is required.

Thanks,
Prathiba

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Apr 2013, 03:38 AM
Hi,

RadNumeric textbox supports get_value() method. Try setting the value using that method.
tempValue = sumInput.get_value() - sender.get_value();

Thanks,
Shinu

0
Prathibarani
Top achievements
Rank 1
answered on 22 Apr 2013, 04:08 AM
Thanks Shinu for response. But if I use your get_value, it errors for sumInput.get_value(). It is fine with sender since sender is RadNuemeric Text box. sumInput is variable declared globally. So, I removed get_value and it is fine now. sumInput - sender.get_value(). I am not sure this is right way to do.

Regarding this, Load event used on 'OnLoad' of footer textbox doesn't get fired everytime textbox leaves focus. It gets fired for the first time when RadNumericTextbox is clicked. after that it won't.

<

 

 

FooterTemplate>

 

 

 

<telerik:RadNumericTextBox ID="rntAmountTotal" runat="server" Type="Currency" Width="75%" CssClass="rightalign">

 

 

 

<ClientEvents OnLoad="Load" />

 

 

 

</telerik:RadNumericTextBox>

 

 

 

</FooterTemplate>

 



Please let me know how to handle this.

Thanks,
PK
0
Princy
Top achievements
Rank 2
answered on 23 Apr 2013, 06:04 AM
Hi,

Try using OnBlur event which occurs when the control loses focus. Please take a look into this help documentation which describes the Client-Side Events basics of RadInput controls.

Thanks,
Princy.
0
Prathibarani
Top achievements
Rank 1
answered on 24 Apr 2013, 02:45 PM
Thanks Princy for update. OnBlur doesn't work with footer Template TextBox because footer template textbox won't recieve focus for every item template entry automatically.


Prathiba.
0
Princy
Top achievements
Rank 2
answered on 25 Apr 2013, 06:17 AM
Hi Prathibha,

Unfortunately I couldn't replicate the issue you are facing. Here is the Complete code snippet I tried.

ASPX:
<asp:ScriptManager runat="server" ID="ScriptManager1">
</asp:ScriptManager>
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" DataSourceID="SqlDataSource1"
    GridLines="None" OnItemDataBound="RadGrid1_ItemDataBound">
    <ExportSettings>
        <Pdf FontType="Subset" PaperSize="Letter" />
        <Excel Format="Html" />
        <Csv ColumnDelimiter="Comma" RowDelimiter="NewLine" />
    </ExportSettings>
    <MasterTableView ShowFooter="true" AutoGenerateColumns="False" CommandItemDisplay="None"
        CurrentResetPageIndexAction="SetPageIndexToFirst" DataKeyNames="OrderID" Dir="LTR"
        Frame="Border" TableLayout="Auto">
        <RowIndicatorColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType"
            Visible="False">
            <HeaderStyle Width="20px" />
        </RowIndicatorColumn>
        <ExpandCollapseColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType"
            Resizable="False" Visible="False">
            <HeaderStyle Width="20px" />
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="OrderID" DataType="System.Int32"
                FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="OrderID"
                ReadOnly="True" SortExpression="OrderID" UniqueName="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="ShippedDate"
                DataType="System.DateTime" FilterListOptions="VaryByDataType" ForceExtractValue="None"
                HeaderText="ShippedDate" SortExpression="ShippedDate" UniqueName="ShippedDate">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="ShipCity" FilterListOptions="VaryByDataType"
                ForceExtractValue="None" HeaderText="ShipCity" SortExpression="ShipCity" UniqueName="ShipCity">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn UniqueName="Template1">
                <ItemTemplate>
                    <telerik:RadNumericTextBox ID="TextBox1" runat="server" DbValue='<%# Eval("Freight") %>'>
                        <ClientEvents OnBlur="Blur" OnFocus="Focus" />
                    </telerik:RadNumericTextBox>
                </ItemTemplate>
                <FooterTemplate>
                    <telerik:RadNumericTextBox ID="TextBox2" runat="server">
                        <ClientEvents OnLoad="Load" />
                    </telerik:RadNumericTextBox>
                </FooterTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
        <EditFormSettings>
            <EditColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType">
            </EditColumn>
        </EditFormSettings>
    </MasterTableView>
    <PagerStyle Mode="NextPrevAndNumeric" />
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString3 %>"
    SelectCommand="SELECT TOP 10 * FROM [Orders]"></asp:SqlDataSource>

Javascript:
<script type="text/javascript">
    var sumInput = null;
    var tempValue = 0.0;
    function Load(sender, args) {
        debugger;
        sumInput = sender;
    }
    function Blur(sender, args) {
  
        sumInput.set_value(tempValue + sender.get_value());
    }
    function Focus(sender, args) {
  
        tempValue = sumInput.get_value() - sender.get_value();
    }                       
</script>

C#:
double sum = 0;
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = (GridDataItem)e.Item;
        sum += double.Parse((dataItem["Template1"].FindControl("TextBox1") as RadNumericTextBox).Value.ToString());
    }
    else if (e.Item is GridFooterItem)
    {
        GridFooterItem footer = (GridFooterItem)e.Item;
        footer["ShipCity"].Controls.Add(new LiteralControl("<span style='color: white; font-weight: bold;'>Total freight on this page is:</span> "));
        (footer["Template1"].FindControl("TextBox2") as RadNumericTextBox).Value = Double.Parse(sum.ToString());
    }
}

Thanks,
Princy.

Tags
Grid
Asked by
Prathibarani
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Prathibarani
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or