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 6666941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:52:52+00:00 2026-05-26T02:52:52+00:00

I am data binding to many FormView controls using EF entity instances, but I

  • 0

I am data binding to many FormView controls using EF entity instances, but I have to resort to this ridiculous kludge in order to achieve what I want without using EntityDataSource controls:

propertyHeaderSection.DataSource = new List<PropertyDetailsModel> { _propertyDetails };

I suspect I will have to derive my own control from FormView and enable it to accept an almost POCO as a data source. Where do I start?

  • 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-26T02:52:53+00:00Added an answer on May 26, 2026 at 2:52 am

    This is my implementation, sort of the same idea as patmortech, but i also found out that the ValidateDataSource method on the BaseDataBoundControl is what throws the exception at run-time if your datasource isn’t enumerable.

    public class CustomFormView : System.Web.UI.WebControls.FormView
        {
            public override object DataSource
            {
                get
                {
                    if (!(base.DataSource is IEnumerable))
                        return new[] {base.DataSource};
    
                    return base.DataSource;
                }
                set
                {
                    base.DataSource = value;
                }
            }
    
            // This method complains at run time, if the datasource is not 
            // IListSource, IDataSource or IEnumerbale
            protected override void ValidateDataSource(object dataSource)
            {
                //base.ValidateDataSource(dataSource);
            }
        }
    

    EDIT:

    Considering the suggestion, i’ve made some changes to the way i check if the assigned DataSource is enumerable or not. I have also managed to create a sample app (VS 2010 Solution) to demo the changes. The app can be downloaded from http://raghurana.com/blog/wp-content/attachments/FormViewDataProblem.zip

    In short this is what i am checking to ensure that the existing datasource can be enumerated already or not:

    public static bool CanEnumerate( this object obj )
        {
            if (obj == null) return false;
    
            Type t = obj.GetType();
    
            return t.IsArray ||
                   t.Implements(typeof (IEnumerable).FullName) ||
                   t.Implements(typeof (IListSource).FullName) ||
                   t.Implements(typeof (IDataSource).FullName);
        }
    

    Please feel free to suggest more changes, if this isnt quite the desired functionality. Cheers.

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

Sidebar

Related Questions

I have an ADO .Net Entity Data Model for my database. In this Model
Concerning data binding I have these classes: public class Foo : List<Bar> { public
How do I use data-binding from code (C# or VB)? This is what I
How is data binding in C# WinForms supposed to work when you have a
I am a learner and i have a problem data binding the dataset. Please
I am using the Flex PopUpButton & data binding a Menu object to the
I'm fairly new to Data binding & XAML, so this probably is fairly simple
I have a classic CoreData application, displaying it's data in NSTableView with Binding (all
I have a data object that has many different List properties. I want to
I have an entity Tag (in core data) that have some attributes and a

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.