Tuesday, March 20, 2012

Pulling HTML out of a Database

Good Morning,

I'm not quite sure this is the right place to post this, but i'll try anyway.

I have a website where I allow people to create their own layouts in HTML, and in the HTML I have them placeing markers (eg. |1| ) where they would like to place something from a database. All the HTML is stored in a SQL Server DB, and when I pull it out, it's fine, except it won't allow me to Replace any of the markers with values from the DB.

Here's and example line of HTML that's held in the DB:

<table width='50%' border='1'><tr><td>|0|</td><td>|1|</td></tr>

and when I do a strHtml.Replace("|0|", dReader["somefield"].ToString()) or even just a strHtml.Replace("|0|", "Test") it never changes it.

Anyone have any ideas?

Thanks,

Deepthought

String.Replace returns a new string with the values replaced. Should be doing something like this in your code

strHtml= strHtml.Replace("|0|", dReader["somefield"].ToString())

No comments:

Post a Comment