470,594 Members | 1,444 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

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.


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

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
users.Add(new User("John", "Doe"));
users.Add(new User("Jane", "Doe"));
users.Add(new User("Joe", "Bloggs"));
this.gvMain.DataSource = users;

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 1130

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by CodeRazor | last post: by
10 posts views Thread by jcc | last post: by
12 posts views Thread by Daniel Klein | last post: by
12 posts views Thread by Peter Van Wilrijk | last post: by
reply views Thread by Tony Johansson | last post: by
2 posts views Thread by puzzlecracker | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.