473,769 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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" AutoGenerateCol umns="false">
<Columns>
<asp:BoundFie ld DataField="Firs tName" HeaderText="Fir st Name" />
<asp:BoundFie ld DataField="Last Name" HeaderText="Las t Name" />
</Columns>
</asp:GridView>

Code Behind

using System;
using System.Collecti ons.Generic;
using System.Web.UI;
using System.Web.UI.W ebControls;
namespace Research
{
public partial class _Default : Page
{
protected void Page_Load(objec t sender, EventArgs e)
{
if (!this.IsPostBa ck)
{
List<IReadOnlyU serDatausers = new
List<IReadOnlyU serData>();
users.Add(new User("John", "Doe"));
users.Add(new User("Jane", "Doe"));
users.Add(new User("Joe", "Bloggs"));
this.gvMain.Dat aSource = users;
this.gvMain.Dat aBind();
}
}
}

public interface IReadOnlyUserDa ta
{
string FirstName { get; }
string LastName { get; }
}

public class User : IReadOnlyUserDa ta
{
private string _givenNames;
private string _surname;

public User() { }

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

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

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

string IReadOnlyUserDa ta.FirstName
{
get { return this._givenName s; }
}

string IReadOnlyUserDa ta.LastName
{
get { return this._surname; }
}
}
}
Apr 24 '07 #1
0 1244

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

Similar topics

5
1556
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 happens when i know that a library must have some method, say void StoreXML ( string XMLmsg ) but want to late bind, as in, only at run time, decide which library i wish to use.
5
5079
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 method. Type t = Type.GetType("MyAssembly.MyClass"); Object obj1 = Activator.CreateInstance(t); obj1.GetType().InvokeMember("MyMethod",BindingFlags.Default,null,obj1,new object{});
10
2753
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 'System.Collections.IEnumerable.GetEnumerator()'. 'HelloWorld.A.GetEnumerator()' is either static, not public, or has the wrong return type. class A : IEnumerable<string>
12
1556
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 are more than two classes involved but two will suffice to explain the problem), and each class has a Copy() method as follows: Public Function Copy() As Object Implements ICloneable.Clone
7
1580
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. Then I would call methods on it. The issue is that frmParent can be any form of my applications and therefore I have to do:
12
1974
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
2221
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). All classes that implement this interface are shown in a drop down in a DataGridViewComboBoxColumn named Validator. By choosing the class to validate this specific data in the drop downbox IValidator<T>.Validate is called and returns true/false....
0
2228
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 pointing to the top interface which is correct. If I instead have a class that implement an interface these will not be shown with arrows in the class diagram. What is the reason for not using
2
1907
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, implementation. Also, if you implement more than two interfaces with the same method, which is rarity in practice or so it seems. To me it appears a shallow end... Am I missing something? Thanks
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.