Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Binding Bug Using Explicit Interface Implementation In C#.

Reply
Thread Tools

Binding Bug Using Explicit Interface Implementation In C#.

 
 
Brandon Driesen
Guest
Posts: n/a
 
      04-24-2007
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<IReadOnlyUserData> users = 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; }
}


}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
'IWebPartField.GetFieldValue' in explicit interface declaration is not a member of interface rote ASP .Net 0 10-30-2008 07:36 AM
Explicit instantiation of STL vector demands explicit instantiation of all the templates it using internally. krunalbauskar@gmail.com C++ 1 12-25-2006 03:51 PM
What's the difference betwwen explicit instantiaion and explicit specialization? Andy C++ 5 01-30-2005 11:46 PM
Is explicit template qualification required for explicit delete? J.T. Conklin C++ 1 08-11-2004 02:06 AM
Data Binding - using inline code vs. functions vs. straight binding Jordan ASP .Net 2 02-10-2004 08:32 PM



Advertisments