Validating aggregate sum value on update and insert

8 posts, 0 answers
  1. Nizar
    Nizar avatar
    8 posts
    Member since:
    May 2011

    Posted 18 Jun 2011 Link to this post

    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
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 Jun 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Nizar
    Nizar avatar
    8 posts
    Member since:
    May 2011

    Posted 21 Jun 2011 Link to this post

    Excellent!!! Thanks Princy for your help :) Very much appreciated.
  5. Nizar
    Nizar avatar
    8 posts
    Member since:
    May 2011

    Posted 27 Jul 2011 Link to this post

    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.
  6. MBEN
    MBEN avatar
    159 posts
    Member since:
    Nov 2011

    Posted 01 Sep in reply to Nizar Link to this post

    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?

     

  7. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 06 Sep Link to this post

    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.
  8. MBEN
    MBEN avatar
    159 posts
    Member since:
    Nov 2011

    Posted 07 Sep in reply to Eyup Link to this post

    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?

  9. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1795 posts

    Posted 12 Sep Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017