• 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
0
tonelm54
Asked:
tonelm54
  • 4
  • 3
  • 2
1 Solution
 
jmwheelerCommented:
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?
0
 
rahkimfCommented:
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?
0
 
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">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSource1" 
            EmptyDataText="There are no data records to display.">
            <Columns>
                <asp:BoundField DataField="fileID" HeaderText="fileID" 
                    SortExpression="fileID" />
                <asp:BoundField DataField="fileName" HeaderText="fileName" 
                    SortExpression="fileName" />
                <asp:BoundField DataField="fileDescription" HeaderText="fileDescription" 
                    SortExpression="fileDescription" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:testConnectionString1 %>" 
            ProviderName="<%$ ConnectionStrings:testConnectionString1.ProviderName %>" 
            SelectCommand="SELECT [fileID], [fileName], [fileDescription] FROM [Table1]">
        </asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>

Open in new window

Clipboard01.jpg
Clipboard02.jpg
0
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.

 
rahkimfCommented:
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.
0
 
tonelm54Author Commented:
Tried both <br> and <br /> still nothing :-(
br.jpg
br-.jpg
0
 
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

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

Open in new window

0
 
jmwheelerCommented:
Add HtmlEncode="false" to that column.

<asp:BoundField DataField="fileDescription" HeaderText="fileDescription" HtmlEncode="False"
                    SortExpression="fileDescription" />
0
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