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

Grouping on GridViewTextBoxColumn having DisableHTMLRendering = false

10 Answers 75 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lester
Top achievements
Rank 1
Lester asked on 05 Mar 2011, 02:30 PM
Hi,

I am using Telerik Q3 2010 on Visual Studion 2008 and C# as the Language for development.
As part of our requirement we need to open up a browser on clicking of a postcode within the address (one of the columns) of the GridView.
When I select the address column as a Group by element, the text within the column is shown as it is.
Is there anyway of setting the DisableHTMLRendering of the group Headers to FALSE or any property within  the GridView to achieve the same functionality.

Please see sample code below and screen shots attached for more details.

 

private void Form1_Load(object sender, EventArgs e)

 

 

{

 

radGridView1.BeginUpdate();

 

radGridView1.AutoSizeRows =

true;

 

 

radGridView1.EnableFiltering =

true;

 

 

radGridView1.AutoScroll =

true;

 

 

radGridView1.ShowGroupPanel =

true;

 

 

radGridView1.EnableHotTracking =

true;

 

 

radGridView1.EnableAlternatingRowColor =

true;

 

 

radGridView1.AllowAddNewRow =

false;

 

 

radGridView1.AutoGenerateColumns =

false;

 

 

radGridView1.BestFitColumns();

 

radGridView1.AllowAutoSizeColumns =

true;

 

radGridView1.AutoSizeColumnsMode =

GridViewAutoSizeColumnsMode.Fill;

 

 

radGridView1.Controls.Clear();

 

radGridView1.ReadOnly =

true;

 

 

radGridView1.Columns.Add(

new GridViewTextBoxColumn("Name"));

 

 

radGridView1.Columns.Add(

new GridViewTextBoxColumn("Address"));

 

 

radGridView1.Columns[1].DisableHTMLRendering =

false;

 

 

radGridView1.Columns[1].WrapText =

true;

 

 

radGridView1.Columns[1].ReadOnly =

true;

 

 

 

 

radGridView1.Rows.Add(

"Lester","<html>21 Yeoman Way <a href=http://maps.google.co.uk/maps?q=BA140QL>BA140QL</a></html>");

 

 

radGridView1.Rows.Add(

"XYX","<html>22 Yeoman Way <a href=http://maps.google.co.uk/maps?q=BA140QL>BA140QL</a></html>");

 

 

radGridView1.Rows.Add(

"ABC","<html>23 Yeoman Way <a href=http://maps.google.co.uk/maps?q=BA140QL>BA140QL</a></html>");

 

 

radGridView1.Rows.Add(

"QEP","<html>24 Yeoman Way <a href=http://maps.google.co.uk/maps?q=BA140QL>BA140QL</a></html>");

 

radGridView1.EndUpdate(

true);
}

 

10 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 05 Mar 2011, 04:36 PM
Hello,

If you include the HTML in your datasource, then the HTML will show as text in the grouping row. However, if you leave out the HTML formatting and add this to the e.CellElement.Text property using the CellFormatting event, then you can format the required text as HTML and still retain the value (which will be displayed in the grouping row) when you group by that column

For more information on CellFormatting please see this help topic
If you need further information, please let me know
Regards,
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 08 Mar 2011, 07:28 PM
Hello
Did this help? If so please remember to mark as answer.
If you need further assistance, please let me know
Thanks
Richard
0
Lester
Top achievements
Rank 1
answered on 09 Mar 2011, 09:56 AM
Hi Richard,

I have a problem formatting the Cell at runtime, as I need to identify the postcode from the entire address and then provide it a hyperlink.
However, this was easy to identify at the datasource level where the address was being constructed.

Do you have any other options by means of which I can provide a hyperlink to part of the text in a GridViewColumn?

0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 09 Mar 2011, 10:05 AM
Hello,

The Telerik controls are built on top of the TPF (Telerik Presentation Foundation) and most support HTML Like formatting. The recognised way is providing HTML for the RadGridView either via the datasource which has the problem that the text and the value will be the same and therefore will show the text value (the HTML) in the grouping row. Using the CellFormatting is the other way.

You might also be interested in this help topic on HTML Like formatting

I hope that this helps but please let me know if you need further information
Thanks
Richard
0
Lester
Top achievements
Rank 1
answered on 09 Mar 2011, 10:33 AM
Hi Richard,

Thanks a lot for your help so far on this topic. I should appreciate the prompt response.

However with regards to this problem, I have disabled grouping on the Address column as it doesn't seem logical to do so.

Thanks,
Lester
0
Richard Slade
Top achievements
Rank 2
answered on 09 Mar 2011, 10:36 AM
You're welcome. If there is anything else you need, please let me know
Thanks
Richard
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 10 Mar 2011, 10:12 AM
Hello again,

My apologies, I should have thought of this earlier, but you can ensure that HTML is shown in the group header. Please see this forum answer for information

I hope that this helps
Richard
0
Lester
Top achievements
Rank 1
answered on 10 Mar 2011, 11:54 AM
Thanks a lot Richard ..

This solves my problem completely. Now My groupings shows with the HTML rendering i.e. without <html> text.

Many Thanks,

Lester
0
Richard Slade
Top achievements
Rank 2
answered on 10 Mar 2011, 11:56 AM
You're welcome. Sorry I didn't give you this information earlier.
All the best
Richard
0
Stefan
Telerik team
answered on 10 Mar 2011, 12:33 PM
Hello Lester,

Another approach is to set the DisableHtmlRendering property of the desired column to false by making use of the ViewCellFormatting event. Then in the GroupSummaryEvaluate event you can format the string in order to display corrent HTML:
void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    GridGroupContentCellElement cell = e.CellElement as GridGroupContentCellElement;
    if (cell != null)
    {
        cell.DisableHTMLRendering = false;
    }
}
 
void radGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
    if (e.Value.ToString().Contains("<html>"))
    {
        e.FormatString = "{1}";
        e.Value = e.Value.ToString().Insert(6, e.SummaryItem.Name + ": ");
    }
}

I hope this helps.

Kind regards,
Stefan
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
Lester
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Lester
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or