473,379 Members | 1,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 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 1227

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,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.