C # HTML tags inside GridView

I have a SharePoint web part that I wrote in C # that is used to display SQL Server data based on user preferences. I retrieve the data using the DataReader, populate the DataSet and set this DataSet as a data source in the GridView and add this control to my page:

GridView outputGrid = new GridView();
outputGrid.CssClass = "OutputGrid";
outputGrid.DataSource = flipped_ds1;
outputGrid.RowDataBound += outputGrid_RowDataBound;
outputGrid.DataBind();
Controls.Add(outputGrid);

This gives me a simple HTML table with a declared CSS class and more. The only problem I encountered is that line breaks in data fields are not displayed at all. I just get a block of text that ignores the breaks that are present in the database when it is displayed in HTML. Coming through my code, I see that the lines of a new line are included in the text in the form "\ r \ n". I tried the regex:

Regex rgx = new Regex("\r\n");
string inputStr = Convert.ToString(dr[x]);
string outputStr = rgx.Replace(inputStr, "<br />");
newRow[ds3.Tables["Bobst Specs 3"].Columns[x]] = outputStr;

, "
" . HTML , "
":

&lt;br /&gt;

SQL- - :

SELECT REPLACE (fldCustomerName, '. ', '.' + @NewLineChar)

, -, . , , , , , . , , , .

+3
3

HTML

<asp:BoundField DataField="MyColumn" HtmlEncode="false" />


,

UPDATE: , gridview, , \n <br />, . - br, html. gridview. . , ,

HTML GridView

+13

\n \r\n

<br /> <br>

0

HTML, :

  • # regex - "$ MYNEWLINE $"
  • HTML :

    <script type="text/javascript">
        function changeNewLines(){
        var inner_html = document.getElementById('theIDofyourgeneratedtable').innerHTML;
        var new_inner_html = inner_html.replace('$MYNEWLINE$', '<BR/>');
        document.getElementById('theIDofyourgeneratedtable').innerHTML = new_inner_html;
        }
        window.onload = changeNewLines;
    </script>
    
  • JQuery, .

0
source

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


All Articles