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?

5
  • 2
    FWIW you shouldn't do your HTML formatting in SQL. Return two data fields and format your grid accordingly. Commented Nov 10, 2009 at 21:49
  • that makes sense , but how do you format 2 boundfields into one? Commented Nov 10, 2009 at 21:51
  • 1
    I would use a template field and lay out accordingly. aspnet101.com/aspnet101/tutorials.aspx?id=58 Commented Nov 10, 2009 at 21:55
  • thanks, this is an alternative, but for now, setting htmlencode worked easier for me Commented Nov 10, 2009 at 21:59
  • Possible duplicate of How do I break the a BoundField's HeaderText Commented Oct 1, 2019 at 4:19

2 Answers 2

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" />
Sign up to request clarification or add additional context in comments.

3 Comments

This is exaclty it - unless you flag the column as 'nowrap' HTML will wrap w/o the linebreak
<br /> doesnt seem to work as it just adds <br /> to the text now and doesnt parse it as html in the boundfield :(
HtmlEncode="false" is not recommended due to potential XSS attacks learn.microsoft.com/en-us/dotnet/api/…
0

Try combining carriage return with line feed:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.