Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6995875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:05:08+00:00 2026-05-27T20:05:08+00:00

I am populating a DataTable using ADO.NET and binding a DataList and it works.

  • 0

I am populating a DataTable using ADO.NET and binding a DataList and it works. But when I try to extract only 10 records using Linq from DataTable as shown below, my code gives an error:

var xx=dt.asEnumerable().take(10).tolist();
dglist.datasource=xx;
dglist.databind();

<asp:DataList ID="dglist" runat="server" 
    RepeatColumns="4" RepeatDirection="Horizontal" 
    RepeatLayout="Table" CellPadding="1">
    <ItemTemplate>
        <div>
           <asp:Image runat="server" id="Image1" 
                 src='<%# Eval("photos") %>'  BorderWidth="0"
                 alt="" style="width:300px;height:300px;display:block;"/>
        </div>
    </ItemTemplate>
</asp:DataList>

My DataTable has one column called “photos”. I am getting an error when I bind to a DataList. Please guide me on how I can use Linq to extract 10 records from DataTable and bind DataList with 10 records.

I have another question.

What does datatable.asEnumerable() mean and what it does do? It seems to convert a DataTable by asEnumerable() but to what?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:05:09+00:00Added an answer on May 27, 2026 at 8:05 pm

    The DataTable implements the IListSource interface that is way it’s supports databinding to column names (so Eval("photos") works). But when you call AsEnumerable() on the DataTable it will return an IEnumerable<DataRow> where the DataRow objects won’t have the property named photos that is why you get the exception. But you can make it work if you use an indexer in your eval with the column name:

    var xx = dt.AsEnumerable().Take(10).ToList();
    dglist.DataSource = xx;
    dglist.DataBind();
    
    <asp:DataList ID="dglist" runat="server" 
        ...
               <asp:Image runat="server" id="Image1" 
                     src='<%# Eval("[photos]") %>'  BorderWidth="0"
                     alt="" style="width:300px;height:300px;display:block;"/>
        ...
    </asp:DataList>
    

    Or you use the AsDataView() extension method. The OfType<object>() is required to make the non generic collection to a generic one to support LINQ. In this case you don’t need to use an indexer in your Eval method:

    var xx = dt.AsDataView().OfType<object>().Take(10).ToList();
    dglist.DataSource = xx;
    dglist.DataBind();
    
    <asp:DataList ID="dglist" runat="server" 
        ....
               <asp:Image runat="server" id="Image1" 
                     src='<%# Eval("photos") %>'  BorderWidth="0"
                     alt="" style="width:300px;height:300px;display:block;"/>
        ....
    </asp:DataList>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET DataTable which I am populating from another set of ASP:TextBox
Does anyone have an example of using of populating a YUI DataTable with a
I'm just getting started using ADO.NET and DataSets and DataTables. One problem I'm having
I'm using the following function to map columns from a DataTable (passed from the
I am populating a DataTable and then binding this to a GridView control. However,
Using C# / .NET 3.5. Currently I'm populating 2 DataTables one after the other
I'm populating a datagrid using Linq--standard kind of stuff (code below). For some reason
I'm using an AutoCompleteExtender in ASP.NET/C# to retrieve data from my database, along with
I'm using a DataGridView to load data from a DataTable. This DataGridView is located
Im populating a GridView from List so am forced to use TemplateField controls to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.