472,985 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,985 software developers and data experts.

Binding Bug Using Explicit Interface Implementation In C#.

The following illustrates my question. Why is it when I bind to an a
collection of items whose interface implementation is explicit, there is
an error during the binding process wherein the error is as follows:

A field or property with the name 'FirstName' was not found on the
selected data source.

Seems to me there is a shortcoming of the Binding Process to Web
Controls. There should not be any impediment doing what I am doing since
there can be legitimate reasons for using explicit interface implementation.

ASPX Page

<asp:GridView ID="gvMain" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
</Columns>
</asp:GridView>

Code Behind

using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Research
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
List<IReadOnlyUserDatausers = new
List<IReadOnlyUserData>();
users.Add(new User("John", "Doe"));
users.Add(new User("Jane", "Doe"));
users.Add(new User("Joe", "Bloggs"));
this.gvMain.DataSource = users;
this.gvMain.DataBind();
}
}
}

public interface IReadOnlyUserData
{
string FirstName { get; }
string LastName { get; }
}

public class User : IReadOnlyUserData
{
private string _givenNames;
private string _surname;

public User() { }

public User(string givenNames, string surname)
{
this._givenNames = givenNames;
this._surname = surname;
}

public string GivenNames
{
get { return this._givenNames; }
set { this._givenNames = value; }
}

public string Surname
{
get { return this._surname; }
set { this._surname = value; }
}

string IReadOnlyUserData.FirstName
{
get { return this._givenNames; }
}

string IReadOnlyUserData.LastName
{
get { return this._surname; }
}
}
}
Apr 24 '07 #1
0 1204

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Daniel Bass | last post by:
..Net is great for modulerising libraries, so that all you need do to access a DLL, is simply call Add Reference and wallah, it's as though the library were written in your project. But what...
5
by: CodeRazor | last post by:
How can i load an interface from a dll using System.Reflection? I can see how its possible to do this on methods, properties in a class. You create an instance of the class and use the invoke...
10
by: jcc | last post by:
Hi guys, I'm a newbie to C#. My Visual Studio 2005 failed to compile the following code with error as 'HelloWorld.A' does not implement interface member...
12
by: Daniel Klein | last post by:
I think I've done my homework and checked around on Google Groups but this seems to be a situation not yet covered. Here is the scenario... There are two classes, Foo and Bar (actually there...
7
by: Sam | last post by:
Hi, Here's my class's constructor: Public Sub New(ByVal frmParent As Form, ByVal curRow As Integer) MyBase.New() End Sub I have a member variable that I want to initialize with frmParent....
12
by: Peter Van Wilrijk | last post by:
Hi, In VB6 I have the following code ... Dim frmLink As Form Set frmLink = Forms.Add(stringformname) frmLink.Show 'wait until all data has been loaded Do Until frmLink.Loaded = 21 DoEvent
0
by: Ken | last post by:
Hi I have a little application that does datavalidation. It supports dynamically loaded plugins (you drop a dll with a class implementing IValidator<Tin the same dir as the main application)....
0
by: Tony Johansson | last post by:
Hello! I try to use the class diagram feature in VS 2005 but the drawing is different se below. If I have an Interface that "implement" two other interface these vill be shown with arrows...
2
by: puzzlecracker | last post by:
I don't see the purpose of explicit interface implementation other than to hide its signature in the class that implements it, and, instead, write your own, perhaps with a different signature,...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.