views:

230

answers:

2

I want to create generic drop down list in ASP.net 2.0 using C#, basic concept is which ever Nhibernate object type with which I initialize this list it should populate dropdown with all values from that objects underlying table. Any suggestions how can I achieve this.

+1  A: 

It's difficult to answer without more information.

Are you programming for the desktop? If so which? (linux, windows, mac) Are you programming for the web? What is your web framework if any? What libraries are you using?

Context can, at times, be of primary importance. Provide a few more details and we might be able to stear you in the right direction.

Edit I'm new here and didn't notice your tagged choices. My mistake. Unfortunately I am not a .NET guy.

From my bookmarks check out this reference for a lot of examples: http://www.java2s.com/Tutorial/ASP.NET/CatalogASP.NET.htm

Chadwick
+1  A: 

You could have your classes implement an interface that defines which properties represent the key and value for the drop down list:

public interface IKeyValuePair
{
    int Key { get; }
    string Value { get; }
}

Then create a method that takes an IEnumerable<KeyValuePair> and populates a drop down list. You can use the Linq Convert extension method to convert the collections returned by NHibernate to IEnumerable<KeyValuePair>.

Jamie Ide