• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 564
  • Last Modified:

ASP.net multiline in GridView

Ive got a gridview, which I have already switched to text wrap true, but in my recordset Id like to put things on multiple lines, I have tried vbcrlf and \n and <br> but all to no avail:-

Any ideas how I can force a new line?

Thank you
  • 4
  • 3
  • 2
1 Solution
I have always been able to use <br /> without a problem.  Can you post some of your code so I can see exactly what you are trying to seperate?
Does your recordset contain the line breaks, or are you trying to add them during your display of the records?  In other words, does your db store the information with line breaks or are you trying to add them for presentation sake?
tonelm54Author Commented:
Im using the <br/> in the recordset, but it just shows the <br/> :-(
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <form id="form1" runat="server">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            EmptyDataText="There are no data records to display.">
                <asp:BoundField DataField="fileID" HeaderText="fileID" 
                    SortExpression="fileID" />
                <asp:BoundField DataField="fileName" HeaderText="fileName" 
                    SortExpression="fileName" />
                <asp:BoundField DataField="fileDescription" HeaderText="fileDescription" 
                    SortExpression="fileDescription" />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:testConnectionString1 %>" 
            ProviderName="<%$ ConnectionStrings:testConnectionString1.ProviderName %>" 
            SelectCommand="SELECT [fileID], [fileName], [fileDescription] FROM [Table1]">

Open in new window

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

It looks like it should work.  

The only suggestion I have is to capture the data in the OnRowDataBound event and replace the "<br />" with <br >   ... or the other way around depending on what your db is sending.

Does that make sense?  I think it would work, but there might be a better way.
tonelm54Author Commented:
Tried both <br> and <br /> still nothing :-(
tonelm54Author Commented:
evern tried the following code, all it does is take out the <br> :-(
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        e.Row.Cells(2).Text = Replace(e.Row.Cells(2).Text, "<br>", vbCrLf)
    End Sub
End Class

Open in new window

Did you try to replace <br> with <br>
Try this again...
replace <br> with &lt;br&gt;

Open in new window

Add HtmlEncode="false" to that column.

<asp:BoundField DataField="fileDescription" HeaderText="fileDescription" HtmlEncode="False"
                    SortExpression="fileDescription" />
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now