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.Add Linq Query to List through Looping using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="nauna">nauna</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:ListView ID=&#34;lvCustomers&#34; runat=&#34;server&#34; GroupPlaceholderID=&#34;groupPlaceHolder1&#34; ItemPlaceholderID=&#34;itemPlaceHolder1&#34;&gt; &lt;LayoutTemplate&gt; &lt;table cellpadding=&#34;0&#34; cellspacing=&#34;0&#34;&gt; &lt;tr&gt; &lt;th&gt; CustomerId &lt;/th&gt; &lt;th&gt; ContactName &lt;/th&gt; &lt;th&gt; Country &lt;/th&gt; &lt;/tr&gt; &lt;asp:PlaceHolder runat=&#34;server&#34; ID=&#34;groupPlaceHolder1&#34;&gt;&lt;/asp:PlaceHolder&gt; &lt;tr&gt; &lt;td colspan=&#34;3&#34;&gt; &lt;asp:DataPager ID=&#34;DataPager1&#34; runat=&#34;server&#34; PagedControlID=&#34;lvCustomers&#34; PageSize=&#34;10&#34;&gt; &lt;Fields&gt; &lt;asp:NextPreviousPagerField ButtonType=&#34;Link&#34; ShowFirstPageButton=&#34;false&#34; ShowPreviousPageButton=&#34;true&#34; ShowNextPageButton=&#34;false&#34; /&gt; &lt;asp:NumericPagerField ButtonType=&#34;Link&#34; /&gt; &lt;asp:NextPreviousPagerField ButtonType=&#34;Link&#34; ShowNextPageButton=&#34;true&#34; ShowLastPageButton=&#34;false&#34; ShowPreviousPageButton=&#34;false&#34; /&gt; &lt;/Fields&gt; &lt;/asp:DataPager&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/LayoutTemplate&gt; &lt;GroupTemplate&gt; &lt;tr&gt; &lt;asp:PlaceHolder runat=&#34;server&#34; ID=&#34;itemPlaceHolder1&#34;&gt;&lt;/asp:PlaceHolder&gt; &lt;/tr&gt; &lt;/GroupTemplate&gt; &lt;ItemTemplate&gt; &lt;td&gt; &lt;%# Eval(&#34;CustomerId&#34;) %&gt; &lt;/td&gt; &lt;td&gt; &lt;%# Eval(&#34;ContactName&#34;) %&gt; &lt;/td&gt; &lt;td&gt; &lt;%# Eval(&#34;Country&#34;) %&gt; &lt;/td&gt; &lt;/ItemTemplate&gt; &lt;/asp:ListView&gt;</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { TestEntities entity = new TestEntities(); var query = (from c in entity.TestCustomers select c).ToList(); List&lt;object&gt; result = new List&lt;object&gt;(); foreach (object item in query) { result.Add(item); } lvCustomers.DataSource = result; lvCustomers.DataBind(); } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handle Me.Load If Not Me.IsPostBack Then Dim entity As TestEntities = New TestEntities() Dim query = (From c In entity.TestCustomers Select c).ToList() Dim result As List(Of Object) = New List(Of Object)() For Each item As Object In query result.Add(item) Next lvCustomers.DataSource = result lvCustomers.DataBind() End If End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/hs1Hc0s.jpg" alt="" width="247" height="122" /></p>https://www.aspforums.net:443/Threads/480672/Add-Linq-Query-to-List-through-Looping-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/480672/Add-Linq-Query-to-List-through-Looping-using-C-and-VBNet-in-ASPNet/Mon, 09 Sep 2019 04:12:49 GMT