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

[Solved] How can I add a literal control to a footer?

6 Answers 344 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 25 Feb 2008, 06:23 AM
Hi

I am using C#, ASP.NET 3.5, Visual Studio 2008 and Prometheus Q3 SP1.

I need to add a HTML message to my footer in my RadGrid.

I tried the following:

protected void RadGrid1_ItemCreated(object source, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item.ItemType == GridItemType.Footer)
    {
        GridFooterItem footer = e.Item as GridFooterItem;

        footer.Controls.Add(new LiteralControl("Hello World!"));
    }
}

... but I get the following error:

'TableRow' cannot have children of type 'LiteralControl'.


Basically what I'm trying to achieve is a custom HTML message just above the Page Index row.


Kind regards

Mark Eaton

6 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 25 Feb 2008, 08:08 AM
Hello Mark,

You can add this literal directly in the grid controls collection.

All the best,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark
Top achievements
Rank 1
answered on 25 Feb 2008, 10:30 PM
Hi Vlad

I'm not sure I understand what you mean. I tried the following:

GridFooterItem footer = RadGrid1.MasterTableView.GetItems(GridItemType.Footer)[0] as GridFooterItem;

footer.Controls.Add(new LiteralControl("Hello World!"));


... but I got the same error as before.

Remember, as stated previously, I need this in the footer (which is above the Page Index) and not below it at the bottom of the grid.

Can you also please provide me a working code example.


Kind regards

Mark Eaton

0
Iana Tsolova
Telerik team
answered on 26 Feb 2008, 11:17 AM
Hello Mark,

Can you try with this code:

protected void RadGrid1_ItemCreated(object sender, Telerik.WebControls.GridItemEventArgs e)  
{  
    if (e.Item is GridFooterItem)  
    {  
       Literal literal = new Literal();  
       literal.Text = "Hello World!";  
       e.Item["MyColumnUniqueName"].Controls.Add(literal);  
    }  

This will add the literal in the footer of the column with UniqueName MyColumnUniqueName. More on how to access cells and rows of the Grid find here:
http://www.telerik.com/help/radcontrols/prometheus/?grdaccessingcellsandrows.html

Regards,
Iana
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark
Top achievements
Rank 1
answered on 26 Feb 2008, 10:35 PM

Hi Iana

Thanks for the response. The code example works well, however what I really want may not be possible?

I want this text to stretch across the length of the grid and not restricted to just one column.

For example:
    RadGrid1.Controls.Add(new LiteralControl("Hello World"));

This is not resticted to any one column but stretches across the length of the grid.

Is such a thing possible for the footer?


Kind regards

Mark Eaton

0
Iana Tsolova
Telerik team
answered on 27 Feb 2008, 12:35 PM
Hi Mark,

Thank your for your detailed explanation.
It is possible to stretch your footer across the whole Grid. You need to remove the unnecessary cells of the footer, leave only one then colspan it so it's under all columns. I've prepared a sample for you. Try it and tell us if that helps.

Greetings,
Iana
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark
Top achievements
Rank 1
answered on 29 Feb 2008, 02:19 AM
Hi Iana

That works very well.


Kind regards

Mark Eaton
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Mark
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or