I want to know how to put a line break in a cell of a grid view. Right now, I put
1
1
1
However, this renders as
1 1 1
How do I fix the line breaks so that each digit is displayed on its own row?
I want to know how to put a line break in a cell of a grid view. Right now, I put
1
1
1
However, this renders as
1 1 1
How do I fix the line breaks so that each digit is displayed on its own row?
Add HtmlEncode="False"
to asp:BoundField
and in the text, should have < br/>
for line breaks as:
<asp:BoundField DataField="Address" HeaderText="Address" HtmlEncode="False" />
You'll need to use the <br/>
tag to put a line break in your html.
You can use String.Replace(new char[] { '\n' }, "<br>")
to get the values with line-breaks replaced with <br/>
in C#.
In the GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
you can put:
e.Row.Cells[2].Text = e.Row.Cells[2].Text.Replace("\n", "<br/>");
For whatever column you're updating. My example is for the third column (e.Row.Cells[2])
.
in gridview's rowdatabound event, you can check the cell's value's count of digit, and if that value is bigger than 1, you can add html tag <br />
between them.
but this won't make the digits show in another row, it will still be the same row, just larger (cause it will be for example 3 lines if the value is 111)