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

Multiple lines in a RadGrid cell?

8 Answers 900 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 02 Aug 2010, 10:45 PM
Hi all:

I ahve data that is being displayed in a RadGrid, and some of the data has multiple lines per row. So for example it might be

Col 1     Col 2      Col 3
Row 1   Test 1     1
                            2
                            3
                           

and I need to replicate this display in the RadGrid cell. I tried to build a string thus:

string strRates = 1 + "\r\n" +
                           2 + "\r\n" +
                           3 + "\r\n";

and then display that string in the RadGrid cell, but the result ends up:

Col 1     Col 2       Col 3
Row 1   Test 1     1 2 3

Does anyone know if it is possible to display mutliple rows of data within 1 cell of the RadGrid?

John.

8 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 05 Aug 2010, 09:26 PM
Hello John,

Please try the following:
string strRates = 1 + "<br/>" +
          2 + "<br/>" +
          3 + "<br/>";

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
John
Top achievements
Rank 1
answered on 05 Aug 2010, 09:41 PM
Yes that worked, thanks!

John.
0
Gabriele
Top achievements
Rank 1
answered on 06 Oct 2010, 09:06 PM
I have the same issue but the data I am using in the datagrid cell is coming from a database where the strings are stored using "\r\n". Once I bind the dataset to the datagrid the cvalues are automatically imported and the multiple lines are displayed as one line.

Any solution for this specific case?

Thanks.
0
Daniel
Telerik team
answered on 11 Oct 2010, 09:40 PM
Hello Gabriele,

You can handle the ItemDataBound event and manually replace the \r\n character sequence with HTML line-break tags:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        TableCell myCell = (e.Item as GridDataItem)["MY_COLUMN_NAME"];
        myCell.Text = myCell.Text.Replace("\r\n", "<br/>");
    }
}

I hope this approach is suitable for you.

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Parvez
Top achievements
Rank 1
answered on 03 Nov 2010, 03:36 PM
It works

thanks mate...
0
Martin Roussel
Top achievements
Rank 1
answered on 04 Feb 2013, 07:41 PM
Hi, ive tried this method in order to multi-line my RadGrid with text data coming from my database, and it "works". Ive noticed however that grid data export (tried all formats) stop working when using this. Problem even occurs when no multi-line text exist. Since Admin's provided solution is kinda 'old', is there a better way?

UPDATE: it seems to affect GridTemplateColumn, which im using. It's seem to not affect GridBoundColumn. CSV export seem to be working.

TIA

Martin
0
Daniel
Telerik team
answered on 08 Feb 2013, 11:10 AM
Hello Martin,

I just tried the same approach in a simple, runnable demo and it seems to work as expected. Please test the attached website and let me know if I'm missing something.

Kind regards,
Daniel
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
Martin Roussel
Top achievements
Rank 1
answered on 08 Feb 2013, 03:03 PM
Daniel,

I solved my issue by replacing my GridTemplateColumns by GridBoundColumns that seem to be more export-friendly (especially when the GridTemplateColumn contains more complex non-text controls).

Thanks anyway,

Martin


Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Daniel
Telerik team
John
Top achievements
Rank 1
Gabriele
Top achievements
Rank 1
Parvez
Top achievements
Rank 1
Martin Roussel
Top achievements
Rank 1
Share this question
or