Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 743893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:54:56+00:00 2026-05-14T08:54:56+00:00

I have a SharePoint web part that I wrote in C# which is used

  • 0

I have a SharePoint web part that I wrote in C# which is used to display SQL Server data based on user selections. I pull the data with a DataReader, fill a DataSet with it, and set that DataSet as the DataSource in a GridView and add that 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 that’s about it. The only problem I’m facing is that line breaks in the data fields are not being rendered at all. I’m simply getting a block of text that ignores the breaks that are present in the database when it’s rendered to HTML. In stepping through my code, I see that the newlines are coming in as text in the form of “\r\n”. I tried a 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;

While that does detect and replace the newlines, I merely get the text “
” with no line breaks. In viewing the HTML source, it is inserting the following line where I specify “
“:

&lt;br /&gt;

I also tried changing my SQL query to something along the lines of:

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

This apparently renders more newlines. I can see that they are present, because if I also insert the regex they are affected, but do not create line breaks. I’m not sure how to replace these, and what with, to get the lines to actually break.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:54:56+00:00Added an answer on May 14, 2026 at 8:54 am

    in the grid view disable the HTML render in the wanted column

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

    and in the field put
    as new line for the text you have

    UPDATE:
    what I understood is the new lines are not showing in the gridview, then you tried to force it by replacing \n with <br /> which I agree with you in it. but the next problem the br tag converted into html entity. and you are not using strongly defined columns in gridview. it is auto-generate columns.
    if that so, all your steps are right and one more thing to do

    Prevent HTML encoding in auto-generated GridView columns

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a SharePoint web part which has custom properties that the user
I have a custom Sharepoint 2010 web part that runs the user through a
The Sharepoint 2010 Current User Filter Web Part allows List Web Parts that have
I wrote a custom web part for SharePoint 2007 that loads an existing user
I have developed a web part that has to be deployed on a Sharepoint
I have a web part which uses many SharePoint controls like menu, SPGrid, tool
I have such XML structure which was returned by SharePoint web services. <rs:data ItemCount=4
In SharePoint 2010 I have a visual web part that uses SP.UI.ModalDialog.showModalDialog The dialog
SharePoint newbie here. I have a web part that is attached to SharePoint's edit
I am developping a web part that I can't update on the SharePoint server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.