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

  • Home
  • SEARCH
  • 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 7540245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:35:40+00:00 2026-05-30T07:35:40+00:00

In my .aspx page, I have an <asp:GridView runat=server ID=CustomerGridView> control which I bind

  • 0

In my .aspx page, I have an <asp:GridView runat="server" ID="CustomerGridView"> control which I bind like this:

public partial class InsertCustomer : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewCustomer();
        }
    }

    private void ViewCustomer()
    {
        var manager = new DomainManager();
        var result = manager.FindAll(new Customer());
        this.CustomerGridView.DataSource = result;
        this.CustomerGridView.DataBind();
    }
}

Here is the DomainManager class:

public class DomainManager
{
    readonly StringBuilder _queryBuilder = new StringBuilder();
    private Type _entityType;
    readonly SQLHelper _sqlHelper = new SQLHelper();

    public IEnumerable FindAll<T>(T entity)
    {
        _entityType = entity.GetType();
        var query = string.Format("select * from {0}", _entityType.Name);
        var dt = _sqlHelper.FillDataTable(query);
        return dt.AsEnumerable();
    }
}

The problem is that my grid is not being bound correctly. Why not?

  • 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-30T07:35:41+00:00Added an answer on May 30, 2026 at 7:35 am

    Try changing

    return dt.AsEnumerable(); 
    

    to

    return dt.DefaultView;
    

    Explanation: By default, a GridView binds to actual properties of an object. For example, if the data source is a List<Customer>, then you can bind to the Name property of each Customer. But when the data source is a DataTable of customers, then each customer is represented by a DataRow, and a DataRow does not have a Name property that the GridView can bind to.

    To support dynamic properties, an object must implement the ICustomTypeDescriptor interface. This interface is implemented by DataRowView but not DataRow. By changing the code to return dt.DefaultView (which is a DataView), you provide the GridView with a collection of DataRowView objects that it can bind to.

    Now you might be wondering why

    this.CustomerGridView.DataSource = dt;
    

    works, but

    this.CustomerGridView.DataSource = dt.AsEnumerable();
    

    doesn’t.

    The reason is that DataTable implements the IListSource interface, which tells the GridView “don’t use me as the data source, use my DefaultView instead.” But AsEnumerable() returns a wrapper object that doesn’t implement IListSource, so the GridView doesn’t know how to get to the DefaultView.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a asp.net repeater control in a aspx page, with runat=server and an
I have a Repeater control in my aspx page: <asp:Repeater ID=repeater runat=server EnableViewState=false> <ItemTemplate>
I have this code in my aspx page: <form id=form2 runat=server> <asp:ScriptManager ID=ItemsScriptManager runat=server
I have the following structure in an aspx page: <asp:Panel ID=pnlCust runat=server> <asp:GridView ID=gvMaster
I have an ASP.Net GridView control on an ASPX page hosted on a SharePoint
I have this code in .aspx page <gridview ..... <columns> ............ ........... <asp:templatefield Visible=true
I have the list box control (ASP.NET Control On aspx page, language C# ).
I have a GridView on my aspx page which displays a collection of objects
I have a Default.aspx page in which I have bind a Grid. In the
OK, so this is bugging me. I have a gridview in ASP.net which I've

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.