How to insert a line break in a grid cell?

I want to know how to put a line break in a grid cell. Right now i put

1
1
1

However, this means that

1 1 1

How to fix line breaks so that each digit is displayed on a separate line?

+3
source share
4 answers

Add HtmlEncode="False"in asp:BoundField and in the text should have < br/>for line breaks like:

<asp:BoundField DataField="Address" HeaderText="Address" HtmlEncode="False" />
+6
source

You need to use a tag <br/>to put a line break in your html.

You can use String.Replace(new char[] { '\n' }, "<br>")to get values ​​with string replacement using <br/>in C #.

+2
source

GridView1_RowDataBound(object sender, GridViewRowEventArgs e) :

e.Row.Cells[2].Text = e.Row.Cells[2].Text.Replace("\n", "<br/>");

, . (e.Row.Cells[2]).

0
source

in the rowdatabound gridview event, you can check the number of cell values ​​for a digit, and if this value is greater than 1, you can add an html tag <br />between them.

but this will not cause the numbers to be displayed on another line, it will still be the same line, just more (because it will be, for example, 3 lines if the value is 111)

-1
source

Source: https://habr.com/ru/post/1773599/


All Articles