0

Is it possible to add carriage returns and line feeds into the CommandText of a TableAdapter so the results of the query displays them in an ASP.Net GridView?

Here is part of a query in the TableAdapter I made using the DataSet designer:

SELECT AsthmaTreatment, 
       BookFee, ClinicWhenIll, DateOfBirth, Forename, GPA, Grade, HealthProblems, ID, 
       IllnessDetails, InjuryDetails, InsuranceCompany, InsurancePolicyNumber, 
       LanguagesSpoken, MedicinesTaken, ParentID, 

       (SELECT MotherName + ' *** ' + FatherName + '***' + CHAR(13) + CHAR(10) +
                AddressLine1 + CHAR(13) + CHAR(10) + 
                AddressLine2 + CHAR(13) + CHAR(10) +
                City + ', ' + State + ' ' + Zip AS Expr1 
           FROM Parents WHERE (ID = Students.ParentID)) AS ParentName, 

        PrimaryDoctor, PrimaryDoctorPhone, PrimaryPhone, SecondaryPhone,
        SurgeryDetails, Surname, TuitionFee, email 

   FROM Students 
   WHERE (Forename LIKE '%' + @SearchValue + '%') OR 
         (Surname LIKE '%' + @SearchValue + '%') OR 
         (@SearchValue = 'ALL')

Using the query described above, the GridView data is shown without the carriage returns and line feeds separating the lines of data.

We are looking to show the data like this in the GridView:

Ismail           Eva *** Emad-ud-deen *** 
                 123 Test St
                 Apt. 100
                 New York, NY 10021
Mustafa          Eva *** Emad-ud-deen ***
                 333 First Ave.
                 Unit 3-B
                 Lowell, MA 01852    
Emad-ud-deen
  • 4,734
  • 21
  • 87
  • 152

1 Answers1

0

the problem is the character's themselves. (browsers, html) do not translate char 10 & 13. Browsers do undertand HTML markup, so you can use <p>, <div>, or <br> tags to format the text.

I would do this in the HTML markup though, not the sql statement.

Jason Meckley
  • 7,589
  • 1
  • 24
  • 45
  • Is it possible to have a GridView where each row of data can be shown on several lines within the GridView? – Emad-ud-deen Nov 28 '12 at 19:13
  • you can have 1 html row per row in the data table. you can use template columns for format the data within each cell any way you want. if you need more control over the layout I would recommend a Repeater for readonly data and the ListView control if you want editable data. – Jason Meckley Nov 28 '12 at 19:46
  • Thanks for the replies. Can you provide a link describing how to set up the html row in the DataTable? – Emad-ud-deen Nov 29 '12 at 13:48
  • a `DataTable` is just that, data. formatting is strictly a UI function. formatting would occur in the markup/html template. depending on what control you use to render the data will determine how to setup the templated code. – Jason Meckley Nov 29 '12 at 14:38