Hi phonghue,
In your code you need to find itemPlaceholder Id instead of OPPubDescrip and use Label control.
Refer below sample.
HTML
<asp:ListView runat="server" ID="ListView1" OnItemDataBound="ListView1_ItemDataBound">
<LayoutTemplate>
<div id="itemPlaceholderContainer" runat="server" style="">
<span runat="server" id="itemPlaceholder" />
</div>
<span style="color: #3366ff;"></span>
</LayoutTemplate>
<ItemTemplate>
<asp:Label Text='<%#Eval("ParaGraph") %>' runat="server" ID="lblParaGraph" />
</ItemTemplate>
</asp:ListView>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("ParaGraph");
dt.Rows.Add("Welcome to ASPSnippets.com");
ListView1.DataSource = dt;
ListView1.DataBind();
}
}
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
Label lblMessage = (e.Item.FindControl("lblParaGraph") as Label);
string newString = "";
if (!string.IsNullOrEmpty(lblMessage.Text))
{
newString = lblMessage.Text.Replace(" ", "<br/>");
}
lblMessage.Text = newString;
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.Add("ParaGraph")
dt.Rows.Add("Welcome to ASPSnippets.com")
ListView1.DataSource = dt
ListView1.DataBind()
End If
End Sub
Protected Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As ListViewItemEventArgs)
Dim lblMessage As Label = (TryCast(e.Item.FindControl("lblParaGraph"), Label))
Dim newString As String = ""
If Not String.IsNullOrEmpty(lblMessage.Text) Then
newString = lblMessage.Text.Replace(" ", "<br/>")
End If
lblMessage.Text = newString
End Sub
Screenshot