How to add   in runtime

G

Guest

I create a HTMLTable in my C# code and then add rows and cells into that table.

I'm trying to set top and bottom border for each cell by using stylesheet
and it works as far as cell has some text in it.
If cell has no content at all, the borders do not show up (..strange)

So I tried to insert text inside each cell which has no other content
inside.

Cell content is set in code:
cell.InnerText = " ";

What I wanted to get parsed to HTML:
<td class="demo"> </td>

but instead I got:
<td class="demo">&npsp;</td>

Any solutions?
 
G

Guest

Doh..
nbsp:s seems to work also in web based newsreader.
Maybe this works.

cell.InnerText = "&nbsp;";
 
J

Johannes Hammersen

Hi Jouni,
I'm trying to set top and bottom border for each cell by using stylesheet
and it works as far as cell has some text in it.
If cell has no content at all, the borders do not show up (..strange)

The normal behavior of browsers for an empty cells is not to display them.
So I tried to insert text inside each cell which has no other content
inside.

If you just put an " " (blank/space) in the cell most browsers will still
not display the cell.
but instead I got:
<td class="demo">&npsp;</td>

If you are getting &nbsp; not &npsp; then that is perfectly fine. &nbsp;
(non braking space) is the HTML Representation for space, and it forces the
browser to display that space, and there for the cell.

Hope that helps
Johannes
 
G

Guest

My first message didn't show up correctly.

Output to HTML page was:
<td class="viewCell">&amp;nbsp;</td>
when using cell.InnerText = "&nbsp;";
 
J

Johannes Hammersen

Hi Jouni,

if you use InnerHtml instead of InnerText it should work.

Johannes
 
D

Dave Fancher

I suspect you're having trouble because you're using InnerText rather than
InnerHtml on your HtmlTableCell. The value of InnerText is HTML encoded so
it makes sense that the "&" in "&nbsp;" would be converted to "&amp;".

HTH
 
K

Kevin Spencer

You got what you should get. &nbsp; is the HTML code for a space.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 
E

Eliyahu Goldin

In addition to the other suggestions you can also do

cell.InnerText = "\u00a0";

Eliyahu
 
G

Guest

Thank you Johannes and Dave, InnerHtml worked.

Dave Fancher said:
I suspect you're having trouble because you're using InnerText rather than
InnerHtml on your HtmlTableCell. The value of InnerText is HTML encoded so
it makes sense that the "&" in " " would be converted to "&".

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top