Hi, I am databinding values from a database table to a gridview.In
one of the cells, I have to display multiple strings. All of them should come in a seperate line. In short, I need to add the "New Line" character in the cell text.
Please help. Regards,
They are multiple strings in different fields in the database.
But the problem is, they are concatenated in the SQL query to form a single string.
I want the ability to add a line delimiter when I form the query, so that that line delimiter will be converted to a
new line when the string is displayed in gridview cell.
<br> doesnt work. If I include that as part of my SQL query, i get <br> on the screen, inside the cell. It doesnt get converted to a new line. char(13) is also not working... its translated to a space within the cell.
Is there some special character which can be used within the gridview cell which will be translated to a new line?
I had the same problem, but the thing to do is quite easy. You do not need to convert the column to a TemplateField. Still as a BoundField, just set the "HtmlEncode" field property to "false". Then, the "<br>" tag (and I believe, any other tags) will work.
kamdbuser
Member
1 Points
6 Posts
New Line in a gridview cell
Oct 01, 2007 12:08 PM|LINK
Jos Branders
Contributor
5210 Points
822 Posts
Re: New Line in a gridview cell
Oct 01, 2007 12:27 PM|LINK
Are these multiple strings in different fields of your datasource?
If so, convert the BoundField of your gridview into a TemplateField.
There, in the ItemTemplate, you can add any markup that you want, and you can add multiple fields in the same column.
Jos
kamdbuser
Member
1 Points
6 Posts
Re: New Line in a gridview cell
Oct 01, 2007 03:50 PM|LINK
They are multiple strings in different fields in the database.
But the problem is, they are concatenated in the SQL query to form a single string.
I want the ability to add a line delimiter when I form the query, so that that line delimiter will be converted to a new line when the string is displayed in gridview cell.
Srinika
Member
723 Points
160 Posts
Re: New Line in a gridview cell
Oct 01, 2007 04:41 PM|LINK
U can do what Jos has said or
u may re-write the query as follows:
Select
'a - in a line' + char(13) + 'b - in the next line'Jos Branders
Contributor
5210 Points
822 Posts
Re: New Line in a gridview cell
Oct 01, 2007 08:44 PM|LINK
Why not use "<br>" as a line delimiter?
If that is not possible, use a TemplateField, and use databinding like this:
<%# Eval(myField).ToString().Replace(";","<br>") %>
(this is when the semicolon is your delimiter)
Jos
kamdbuser
Member
1 Points
6 Posts
Re: New Line in a gridview cell
Oct 08, 2007 05:55 AM|LINK
<br> doesnt work. If I include that as part of my SQL query, i get <br> on the screen, inside the cell. It doesnt get converted to a new line. char(13) is also not working... its translated to a space within the cell.
Is there some special character which can be used within the gridview cell which will be translated to a new line?
Jos Branders
Contributor
5210 Points
822 Posts
Re: New Line in a gridview cell
Oct 08, 2007 07:10 AM|LINK
The special character is <br>.
Did you try
<%# Eval(myField).ToString().Replace(";","<br>") %>
as I said before?
Jos
arthur.lopes
Member
4 Points
2 Posts
Re: New Line in a gridview cell
Jan 28, 2008 05:17 PM|LINK
I had the same problem, but the thing to do is quite easy. You do not need to convert the column to a TemplateField. Still as a BoundField, just set the "HtmlEncode" field property to "false". Then, the "<br>" tag (and I believe, any other tags) will work.
Manoj_B
Member
4 Points
6 Posts
Re: New Line in a gridview cell
Dec 01, 2012 06:24 AM|LINK
@arthur.lopes is correct
set the "HtmlEncode" field property to "false". then html tags are works in inside the cell of gridv view.