Bert
Bert

Reputation: 1029

How to split in aspx

I have this code and this one has more than one data from the database

so my expected output is

1.line1

2.line2

but with this code i get

1.line12.line2

but the data from the database have nextline on it.

this is the code

 <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">
 <ItemTemplate>

<%# Eval("News_data") %>

 </ItemTemplate>
 </asp:ListView>

from this database

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TDBSConnectionString %>" 
                            SelectCommand="SELECT [news], [news_date],[news_data] FROM [ibsi.news]">
                        </asp:SqlDataSource>

this is the sample pics.

this is the DB

this is the output

Ouput

when i use pre tag

enter image description here

Upvotes: 0

Views: 306

Answers (2)

balexandre
balexandre

Reputation: 75073

You can easily replace it as that's normally (you own the database, so you will know better) a hidden character like Line Feed char...

if it is, try this:

<%# Eval("News_data").ToString().Replace("\n", "<br/>") %>

This happens for example if you are grabbing the data from a multirow textbox without convert it before.

\n\r is the same as (chr)13 + (chr)10 witch means LF (Line Feed), CR (Carriage Return).

Upvotes: 2

PraveenVenu
PraveenVenu

Reputation: 8337

If you want to do some manipulation, put a template field in the gridview and a span inside

<asp:TemplateField>
    <ItemTemplate>
        <span ID="spnHtml" runat="server">
        </span> 
    </ItemTemplate>
</asp:TemplateField>

Now in the RowDataBound manipulate the data.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        HtmlGenericControl spnHtml = (HtmlGenericControl)e.Row.FindControl("spnHtml");           
        string sHtml = (string)DataBinder.Eval(e.Row.DataItem, "YourDbColumnName");
        spnHtml.InnerHtml = sHtml;
    }

}

Upvotes: 1

Related Questions