Question

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    
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top