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

Inserting Items in to the Footer

4 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Danny
Top achievements
Rank 2
Danny asked on 23 Oct 2012, 05:38 PM
Hello all-

is there a way to assign values to footer items using an integer index?

If so, in what event would you do this?

Thanks in advance.

4 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 26 Oct 2012, 08:24 AM
Hello Danny,

If you want to change the RadGrid footer item you need to handle ItemCreated event and check if e.Item is GridFooterItem. Then you could change its cells by using the columns UniqueName. For example:
void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
      GridFooterItem footerItem = e.Item as GridFooterItem;
      if (footerItem != null)
      {
          footerItem["columnUniqueName"].Text = "SomeValue";
      }
}
However if you want to change the GroupFooterItems you could try using the same approach or you could try using the GroupFooterTemplate. Online example of GroupFooterTemplate you could find here:
http://demos.telerik.com/aspnet-ajax/grid/examples/groupby/headerandfootertemplates/defaultcs.aspx

I hope this helps.

All the best,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Danny
Top achievements
Rank 2
answered on 26 Oct 2012, 05:22 PM
Thanks for the reply, Radoslav.

In gridview I'm able to add items to the footer in the OnRowDataBound event like this:
protected void gridview_OnRowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.Footer)
           {                         
               for(int i = 0; i < dt.columns.count; i++)
               {
                     e.Row.Cells[i].Text = someString[i];

So there's no way to assign the cells in the footer as integer indexes?  I have to use the column names?
0
Accepted
Shinu
Top achievements
Rank 2
answered on 29 Oct 2012, 10:13 AM
Hi,

You can assign values to footer items using an integer index. But the column index starts at index '2' because GridExpandColumn and GridRowindicatorColumn are always in front of data columns. So the most recommended way is to change the value by using the column's UniqueName. Here is the sample code snippet I tried to assign footer cell text using index.

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridFooterItem)
    {
        string[] arr2 = { "one", "two", "three" };
        for (int i = 0; i < dt1.Columns.Count; i++)
        {
           int j = i + 2;
           e.Item.Cells[j].Text = arr2[i];
           j++;
        }    
    }
}

Thanks,
Shinu.
0
Danny
Top achievements
Rank 2
answered on 29 Oct 2012, 06:10 PM
This-

"But the column index starts at index '2' because GridExpandColumn and GridRowindicatorColumn are always in front of data columns"

Thanks Shinu!
Tags
Grid
Asked by
Danny
Top achievements
Rank 2
Answers by
Radoslav
Telerik team
Danny
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Share this question
or