3

I have this string in some sql:

FT_TBL.Title  + CHAR(13) + 'Job:' + str(FT_TBL.JobName) as Title

Now the Title is parsed as a boundfield in a c# gridview, the first row puts "Job" on the next line, but after that its random, some lines are next line some aren't! Any ideas?

David
  • 33
  • 1
  • 3
  • 2
    FWIW you shouldn't do your HTML formatting in SQL. Return two data fields and format your grid accordingly. – n8wrl Nov 10 '09 at 21:49
  • that makes sense , but how do you format 2 boundfields into one? – David Nov 10 '09 at 21:51
  • 1
    I would use a template field and lay out accordingly. http://aspnet101.com/aspnet101/tutorials.aspx?id=58 – n8wrl Nov 10 '09 at 21:55
  • thanks, this is an alternative, but for now, setting htmlencode worked easier for me – David Nov 10 '09 at 21:59
  • Possible duplicate of [How do I break the a BoundField's HeaderText](https://stackoverflow.com/questions/310121/how-do-i-break-the-a-boundfields-headertext) – Michael Freidgeim Oct 01 '19 at 04:19

2 Answers2

11

Instead of char(13) use <br /> for line breaks in HTML.

Note : Do not forget to add HtmlEncode="false" to your columns that show HTML content :

<asp:BoundField DataField="Title" HtmlEncode="false" />
Canavar
  • 47,715
  • 17
  • 91
  • 122
  • 1
    This is exaclty it - unless you flag the column as 'nowrap' HTML will wrap w/o the linebreak – n8wrl Nov 10 '09 at 21:48
  • doesnt seem to work as it just adds
    to the text now and doesnt parse it as html in the boundfield :(
    – David Nov 10 '09 at 21:50
  • HtmlEncode="false" is not recommended due to potential XSS attacks https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.boundfield.htmlencode?view=netframework-4.8 – Michael Freidgeim Oct 01 '19 at 04:12
0

Try combining carriage return with line feed:

FT_TBL.Title  + CHAR(10) + CHAR(13) + 'Job:' + str(FT_TBL.JobName) as Title
Registered User
  • 8,357
  • 8
  • 49
  • 65