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

Validating aggregate sum value on update and insert

7 Answers 153 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nizar
Top achievements
Rank 1
Nizar asked on 18 Jun 2011, 08:32 PM
Hello,

I have a gridBoundColumn with aggregate=sum and I get the total fine. I have a requirement that if the total is not equal to 100 on update and insert, that I cancel the command and display a message. I tried both onUpdateCommand and onItemDataBound, but I can't get the syntax correct. I'm using C#. I would like to use the onUpdateComand and onInsertCommand to check for the aggregate sum value.

Thanks.

Nizar

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Jun 2011, 12:13 PM
Hello Nizar,

Try the following code snippet in InsertCommand event to achieve your scenario.

C#:
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
   {
       GridFooterItem footerItem = (GridFooterItem)RadGrid1.MasterTableView.GetItems(GridItemType.Footer)[0];
       string strtxt = footerItem["ColumnUniqueName"].Text;
       if (strtxt != "100")
       {
           Response.Write("<script language=JavaScript>confirm('Are you sure?');</script>");
       
   }

Thanks,
Princy.
0
Nizar
Top achievements
Rank 1
answered on 21 Jun 2011, 07:06 PM
Excellent!!! Thanks Princy for your help :) Very much appreciated.
0
Nizar
Top achievements
Rank 1
answered on 27 Jul 2011, 04:45 PM
Hi Princy,

I didn't full explain my situation. The column I need to check the aggregate for is called "percentage", and the aggregate sum need to equal 100, or flag a message and halt the insert/update SQL statement. This aggregate sum can be based on one or more rows. I use inline editing. So, upon insert or update, the aggregate sum needs to reflect the changes I just made in the edit mode. Using your code, I only capture the aggregate when the page loaded, not with the changes I just made (either as an update or insert). I'm not using textboxes, just the straight RadGrid automated update/insert scenarios.

Thanks.

nizar d.
0
MBEN
Top achievements
Rank 2
Veteran
answered on 01 Sep 2016, 07:15 PM

Hi,

I have a gridboundcolumn with aggregate = sum, I need to validate the sum to be not more than 100.

How can I get the value of the footer in javascript?

 

0
Eyup
Telerik team
answered on 06 Sep 2016, 10:48 AM
Hello,

You can use the GetItems method to access the footer on PreRender event handler:
http://www.telerik.com/help/aspnet-ajax/grid-using-getitems-getcolumn-methods.html

As for accessing the footer on client-side, you can check the implementations in the attached web site samples.

Regards,
Eyup
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
MBEN
Top achievements
Rank 2
Veteran
answered on 07 Sep 2016, 05:34 PM

Thanks for the response but I am not able to get the footer value using the code you provided. I am calling the javascript function from outside of the grid (on click of a button)

Below is my column definition:

<telerik:GridBoundColumn Aggregate="Sum" DataField="BeneficiaryPercentage" HeaderText="Percentage" DataFormatString="{0:c2}" FooterText="Total: " HeaderStyle-Width="20%" FooterStyle-HorizontalAlign="Right">
</telerik:GridBoundColumn>

Here is my js function :

function rgPrimaryBeneficiaryClientValidation(source, args) {
                var grid = $find('<%= rgPrimaryBeneficiary.ClientID %>');
}

How do i find the footer for the column above in this function and check the value of the footer?

0
Konstantin Dikov
Telerik team
answered on 12 Sep 2016, 10:24 AM
Hi,

You can get reference to the TR element corresponding to the footer with jQuery:
var tdContent = $telerik.$($find("YOURGRIDID").get_element()).find(".rgFooter td")[3].innerHTML(); //where 3 is the index of the column

Hope this helps.


Regards,
Konstantin Dikov
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Nizar
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Nizar
Top achievements
Rank 1
MBEN
Top achievements
Rank 2
Veteran
Eyup
Telerik team
Konstantin Dikov
Telerik team
Share this question
or