Conditional formatting for footer

7 posts, 1 answers
  1. Syed
    Syed avatar
    74 posts
    Member since:
    Mar 2009

    Posted 17 May 2009 Link to this post

    Hi,

    I can able to format the cells of the RadGrid.  I want to format footer and group footer based on some condition like in the following code. 
    Look at the following code which i format for the cell:
    Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound  
            'Is it a GridDataItem  
            If (TypeOf (e.Item) Is GridDataItem) Then  
                'Get the instance of the right type  
                Dim dataBoundItem As GridDataItem = e.Item  
     
                Dim a As New ArrayList  
                a.Add("M9_Sep")  
                a.Add("M10_Oct")  
                a.Add("M11_Nov")  
                a.Add("M12_Dec")  
                a.Add("M1_Jan")  
                a.Add("M2_Feb")  
                a.Add("M3_Mar")  
                a.Add("M4_Apr")  
                a.Add("M5_May")  
     
                For i As Integer = 0 To 8  
                    Dim s As Integer = 0 
                    Integer.TryParse(dataBoundItem(a(i)).Text, s)  
     
                    Select Case s  
                        Case Is > 120  
                            dataBoundItem(a(i)).BackColor = Drawing.Color.Red  
                        Case 90 To 120  
                            dataBoundItem(a(i)).BackColor = Drawing.Color.Green  
                        Case 60 To 89  
                            dataBoundItem(a(i)).BackColor = Drawing.Color.Yellow  
                        Case Is < 60 
                            dataBoundItem(a(i)).BackColor = Drawing.Color.Purple  
                    End Select  
                Next  
            End If 

    Thanks.

    Regards
    Syed Arshad

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 May 2009 Link to this post

    Hi Syed,

    You need to access the footer as GridFooterItem and group footer as GridGroupFooterItem in the ItemDataBound event.

    CS:
     
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridFooterItem) 
            { 
                GridFooterItem pager = (GridFooterItem)e.Item; 
                //apply formatting here 
            } 
            if (e.Item is GridGroupFooterItem) 
            { 
                GridGroupFooterItem footer = (GridGroupFooterItem)e.Item; 
                //apply formatting here 
            } 
       } 


    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Daniel Aquere
    Daniel Aquere avatar
    85 posts
    Member since:
    Mar 2011

    Posted 13 Apr 2011 Link to this post

    Hi Princy and Syed,

    Please, how can I test the value of footer column (sum) in C# to decide what formatting (colors) I use?

    Thanks, best

    Daniel
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Apr 2011 Link to this post

    Hello Daniel,

    You can access the footer column value using UniqueName of the corresponding column.

    C#:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
       {
           if (e.Item is GridFooterItem)
           {
               GridFooterItem footerItem = (GridFooterItem)e.Item;
               if (footerItem["ColumnUniqueName"].Text == "xxx")
               {
                 //your code
               }
           }
       }

    Thanks,
    Princy.
  6. Daniel Aquere
    Daniel Aquere avatar
    85 posts
    Member since:
    Mar 2011

    Posted 02 May 2011 Link to this post

    Hi Princy,

    Works very well.

    Thanks, best

    Daniel
  7. Daniel Aquere
    Daniel Aquere avatar
    85 posts
    Member since:
    Mar 2011

    Posted 01 Aug 2011 Link to this post

    Hi Princy,

    Please, one more doubt...

    In my grid I have four columns:
    1. activity duration
    2. percent_finished of activity (0 to 100)
    3. project duration
    4. activity duration percent (regarding to the project duration) - if the project duration is 100 day and the activity duration is 10 days, this column value is 10%

    I´d like to agregate on footer with "Sum" only the values items with column 2 greater then 0%, but, it´s necessary something like "activity duration" * "percent_finished of activity" to discover the real percent finished.

    Translating, I have a list of activities of project and need to discover the percent finished.

    How to do this in the footer?

    Thanks,

    Daniel
  8. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 04 Aug 2011 Link to this post

    Hi Daniel Aquere,

    I have answered your question in the support thread that you have opened. If you have any further questions on that matter, please post them there to avoid duplicate posts. Here is the answer from the ticket for anyone who could need it:
    You can achieve this through the ItemDataBound event of RadGrid. Since it is first fired for each grid dataitem and then for the footer, you can first sum up the values for each row and then put them in the footer. I did not exactly understand the logic of the calculation but I did a sample one in your project, so that you can see how the implementation works. Then, you can modify it as per your requirement.
    int total;
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem dataItem = e.Item as GridDataItem;
            int fieldValue = int.Parse(dataItem["duracao"].Text) * int.Parse((dataItem["percent_concluido"].FindControl("percent_concluido") as Label).Text);
            total += fieldValue;
        }
        if (e.Item is GridFooterItem)
        {
            GridFooterItem footerItem = e.Item as GridFooterItem;
            footerItem["percent_concluido"].Text = "total: " + total.ToString();
        }
    }


    This is based on the code sample from this documentation article:
    Totals in Grid Footers

    Greetings,
    Tsvetina
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017