Hi
I have a collection of person objects that are added to a dictionary,
each items is added with a unque key. Each person object has a first
name property, and a last name property
My problem is I want to bind this to a dropdown list so that the
DataValueField is set to the ID of the Person, and that the
DataTextField displays the firstname of the person. The problem is I
can only set the DataValueField to either "Key" or "Value", but I want
my value to be "FirstName" When I do this I get an error saying:
Databinding "System.Collect ions.Generic.Ke yValuePair does not contain a
aproperty with the name FirstName"
Am I doing something wrong? Can I actually achive what I am trying to
do? 5 4610
Databinding "System.Collect ions.Generic.Ke yValuePair does not contain a
aproperty with the name FirstName"
Am I doing something wrong? Can I actually achive what I am trying to
do?
Try binding to the Values property of your dictionary.
--
Michal http://vaultofthoughts.net
Hi
I have tried that but it still gives me the same message
Any ideas anyone?
Mikeon wrote:
Databinding "System.Collect ions.Generic.Ke yValuePair does not contain a
aproperty with the name FirstName"
Am I doing something wrong? Can I actually achive what I am trying to
do?
Try binding to the Values property of your dictionary.
--
Michal http://vaultofthoughts.net
Easier than you think.
DropDownList.Da taSource = Dictionary.Valu es;
This works for me. Here's my full sample code which is complete BS of
course but does work.
System.Collecti ons.Generic.Dic tionary<string, Persondict
= new Dictionary<stri ng, Person>();
dict.Add("Rober t", new Person("Robert" , "Turner"));
dict.Add("Fred" , new Person("Fred", "Flinstone" ));
dict.Add("Willm a", new Person("Willma" , "Flinstone" ));
ddl1.DataSource = dict.Values; // ddl1 is the
dropdownlist. but I'm sure you figured that out.
ddl1.DataTextFi eld = "FirstName" ;
ddl1.DataValueF ield = "LastName";
ddl1.DataBind() ;
After rereading your post I think I misunderstood. As I now understand
it, you want the Value to be the Key from the dictionary and the Text
to be the persons first name. As far as I know this cannot be done
using simple databinding. I would suggest that you add the id as part
of the person object as well, allowing you to bind to the Values
property of the dictionary or you will have to enumerate the items in
the dictionary and add each item yourself.
Neither solution is difficult and will give you what I think you want.
Hope you find this helpful.
Ah....
Thats much better!!
I think that placing the id as part of the person object is the way to
go!
Gozirra wrote:
After rereading your post I think I misunderstood. As I now understand
it, you want the Value to be the Key from the dictionary and the Text
to be the persons first name. As far as I know this cannot be done
using simple databinding. I would suggest that you add the id as part
of the person object as well, allowing you to bind to the Values
property of the dictionary or you will have to enumerate the items in
the dictionary and add each item yourself.
Neither solution is difficult and will give you what I think you want.
Hope you find this helpful.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Helium |
last post by:
Is there any need for "System.Collections.Queue" any more? OK, .Net
made the mistake to start without generics, but that is fixed now.
Languages without support for generics could use
"System.Collections.Generics.Queue<Object>" instead of
"System.Collections.Queue". So everytime those languages use a
generic, they just use them with <object>.
I don't think having two different sets of collections is a good idea.
|
by: Arnaud Debaene |
last post by:
Hello all,
One area where the .Net framework 1.1 is really poor is Collections : We've
got very few choice concerning the containers and their characteristics (for
example, ArrayList, Queue and Stack are the only "non-dictionary" avalaible
containers, and only Stack has some complexity specifications).
The worst thing however is the IEnumerator interface, which doesn't allow
for insertion, deletion or even *modification* of an item...
|
by: Gary van der Merwe |
last post by:
Hi
When C# 2.0 arrives System.Collections.Specialized.StringCollection will
become "obsolete". Will the framework still contain this class, or will
there be a C# 1.X to 2.0 conversion utility that will change
System.Collections.Specialized.StringCollection to
System.Collections.ArrayList <string> and ArrayList to ArrayList<object>
??
Gary
|
by: atgraham |
last post by:
Here is the "lead C# architect" attempting to impugn C++ templates
(bottom of the page).
http://www.artima.com/intv/generics2.html (bottom of the page)
(Full article begins at http://www.artima.com/intv/generics.html)
I think every employee at Micrsoft must be required to take a class in
"FUD marketing" before speaking with anyone outside the company. I
think the term "money oriented programming" is suitable here.
|
by: Adam Clauss |
last post by:
I ran into a problem a while back when attempting to convert existing .NET
1.1 based code to .NET 2.0 using Generic collections rather than Hashtable,
ArrayList, etc.
I ran into an issue because the old code allowed me to do what basically was
the following assignment:
class SomeClass
{
private Queue q;
SomeClass(Queue q)
| |
by: riftimes |
last post by:
Hello,
would you help me to find totorials with examples about generics and
Dictionary
thank you.
|
by: Mark Rae |
last post by:
Hi,
Is it possible to use a Dictionary<int, stringor even Dictionary<string,
stringas the DataSource for a DropDownList directly, i.e. without having
to iterate through the the Dictionary's KeyValuePair collection and populate
the DropDownList's Items collection manually?
The DropDownList certainly "understands" the Dictionary object, but the
problem seems to be that there's no way of telling it which element of the
Dictionary object...
|
by: John Grandy |
last post by:
Is it possible to bind a Dictionary to a DropDownList ?
The most obvious code fails :
Dictionary<string,stringdictionary = new Dictionary<string,string>
dictionary.Add("Name1","Value1");
//add some more items ...
DropDownList.DataSource = dictionary;
|
by: pantagruel |
last post by:
Hi,
This is in a windows service in .NET 1.1 I seem to remember reading
somewhere that in .NET 1.1 Windows Services are limited in what
namespaces they can use - is this so? the only thing that seems to be
supported is System.Collections.Specialized.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |