ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.ASP.Net Error: Both DataSource and DataSourceID are defined on ListView1. Remove one definition<p>Hi&nbsp;phonghue,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:ListView ID=&#34;ListView1&#34; runat=&#34;server&#34; DataSourceID=&#34;SqlDataSource1&#34; OnItemDataBound=&#34;ListView1_OnItemDataBound&#34;&gt; &nbsp;&nbsp;&nbsp; &lt;ItemTemplate&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;table&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;p class=&#34;padding4&#34;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:Label ID=&#34;OPPubDescripLabel&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;Content&#34;) %&gt;&#39; Font-Size=&#34;12px&#34; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Font-Names=&#34;Arial&#34; Width=&#34;650px&#34;&gt;&lt;/asp:Label&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/p&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/td&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tr&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/table&gt; &nbsp;&nbsp;&nbsp; &lt;/ItemTemplate&gt; &lt;/asp:ListView&gt; &lt;asp:SqlDataSource ID=&#34;SqlDataSource1&#34; runat=&#34;server&#34; ConnectionString=&#34;&lt;%$ ConnectionStrings:TestConnectionString %&gt;&#34; &nbsp;&nbsp;&nbsp; SelectCommand=&#34;SELECT * FROM [HTMLContent]&#34;&gt;&lt;/asp:SqlDataSource&gt;</pre> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">protected void ListView1_OnItemDataBound(object sender, ListViewItemEventArgs e) { &nbsp;&nbsp;&nbsp; Label lblMessage = (e.Item.FindControl(&#34;OPPubDescripLabel&#34;) as Label); &nbsp;&nbsp;&nbsp; if (!string.IsNullOrEmpty(lblMessage.Text)) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblMessage.Text = lblMessage.Text.Replace(&#34;\\r&#34;, &#34;&lt;br/&gt;&#34;); &nbsp;&nbsp;&nbsp; } }</pre> <p><span style="text-decoration: underline;"><strong>VB.Net</strong></span></p> <pre class="brush: vb">Protected Sub ListView1_OnItemDataBound(ByVal sender As Object, ByVal e As ListViewItemEventArgs) Handles ListView1.ItemDataBound &nbsp;&nbsp;&nbsp; Dim lblMessage As Label = (TryCast(e.Item.FindControl(&#34;OPPubDescripLabel&#34;), Label)) &nbsp;&nbsp;&nbsp; If Not String.IsNullOrEmpty(lblMessage.Text) Then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim newString As String = lblMessage.Text.Replace(Strings.Chr(13), &#34;&lt;br/&gt;&#34;) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblMessage.Text = newString &nbsp;&nbsp;&nbsp; End If End Sub</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <p><img src="https://i.imgur.com/nzywu1J.jpg" alt="" width="245" height="329" /></p>https://www.aspforums.net:443/Threads/615441/ASPNet-Error-Both-DataSource-and-DataSourceID-are-defined-on-ListView1-Remove-one-definition/https://www.aspforums.net:443/Threads/615441/ASPNet-Error-Both-DataSource-and-DataSourceID-are-defined-on-ListView1-Remove-one-definition/Thu, 09 May 2019 03:17:10 GMT