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

Programmatically Create GridFooterTemplate

3 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Satz
Top achievements
Rank 1
Satz asked on 08 Nov 2013, 03:01 PM
Hi ,

How to create GridFooterTemplate programmatically for autogenerate column is true?  

For the below type of aspx code

<GroupFooterTemplate>
                          Total Refund Amount:
                          <asp:Label runat="server" ID="lblTotalSum" Text='<%# Eval("RefundAmount") %>'></asp:Label>
                           Total Count:
                          <asp:Label runat="server" ID="Label1" Text='<%# Eval("Id") %>'></asp:Label>
                      </GroupFooterTemplate>

Best Regards,
Satz

3 Answers, 1 is accepted

Sort by
0
Satz
Top achievements
Rank 1
answered on 11 Nov 2013, 04:33 AM
Hi,

Any help on this?

Best Regards,
Satz
0
Princy
Top achievements
Rank 2
answered on 12 Nov 2013, 12:01 PM
Hi Satz,

Please try the following code snippet.

C#:
RadGrid RadGrid1;
protected void Page_Init(object sender, EventArgs e)
{
    RadGrid1 = new RadGrid();
    RadGrid1.DataSourceID = "SqlDataSource1"
    RadGrid1.AllowPaging = true;
    RadGrid1.AutoGenerateColumns = false;   
     
    RadGrid1.ShowFooter = true;
    RadGrid1.MasterTableView.ShowGroupFooter = true;
    RadGrid1.ShowGroupPanel = true;
    RadGrid1.ClientSettings.AllowDragToGroup = true;
  
    // Creating a GroupFooterTemplate class
    RadGrid1.MasterTableView.GroupFooterTemplate = new MyGroupFooterTemplate();   
      
    PlaceHolder1.Controls.Add(RadGrid1);
}
    public class MyGroupFooterTemplate : ITemplate
    {   
        protected Label labControl;     
        public void InstantiateIn(System.Web.UI.Control container)
        {
           labControl = new Label();
           labControl.ID = "labelControl";     
           labControl.DataBinding += new EventHandler(lControl_DataBinding);     
           container.Controls.Add(labControl);
        }
  
        public void lControl_DataBinding(object sender, EventArgs e)
        {         
            Label lab = (Label)sender;      
            GridGroupFooterItem footerItem = (GridGroupFooterItem)lab.NamingContainer;
            //Bind the required value to the Label Text
            lab.Text = "Your Required Value";     
        }         
    }

Thanks,
Princy
0
Satz
Top achievements
Rank 1
answered on 12 Nov 2013, 12:53 PM
Hi Princy,

Thanks for the reply :).

My requirement is that i need to dynamically sum or count the grouping columns . So i ended up in  below code. 

 <asp:Label runat="server" ID="OrderLbl"  Visible='<%# 
col("OrderId")==string.Empty?false:true%>' Text='<%# "Total Order
Count:"+ col("OrderId")%>' ></asp:Label><BR>
  
  
  
 protected object col(string columnName)
        {
            foreach (GridColumn col in radgrid1.MasterTableView.AutoGeneratedColumns)
            {
                if (col.UniqueName.Equals(columnName))
                {
                    return Eval(columnName);
                }
            }
            return string.Empty;
        }



Best Regards,
Satz
Tags
Grid
Asked by
Satz
Top achievements
Rank 1
Answers by
Satz
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or