0

I am having a bit of trouble with A dropdownlist that is supposed to be populated with values that correspond to ID keys in a database. So ideally i want something that looks like this in the dropdown list

value="0" USA value="1" ETC

and my code behind looks like this

    public TabletViewModel(Tablet tablet)
    {
        Tablet = tablet;
        //AreaHelper.Areas, tablet.Location.Name
        Areas = new SelectList(AreaHelper.Areas, tablet.Location.Name);
    }

whenever I try to add overflow methods to the selectlist constructor I get exception errors when I try to add the LocationID

anyone have any ideaS?

3
  • What type of errors are you getting? Commented Sep 18, 2009 at 18:38
  • DataBinding: 'System.String' does not contain a property with the name 'AWING'. when i change my constructor to : Areas = new SelectList(AreaHelper.Areas, tablet.Location.Name, tablet.LocationID.ToString()); Commented Sep 18, 2009 at 18:41
  • I am new here, can any one tell me what is the 3rd line of the code doing ! Commented Sep 19, 2009 at 14:23

2 Answers 2

1

I figured out the issue, the IEnumerable i was passing was a specific column, not the whole table, so when i tried to do

new SelectList(AreaHelper.Areas, tablet.Location.Name, tablet.LocationID.ToString())

and got the error: "String doesn't contain property Name"

now everything is working fine

Sign up to request clarification or add additional context in comments.

Comments

0

Does your list AreaHelper.Areas support IEnumerable?

Is tablet, tablet.Location or tablet.Location.Name Null?

1 Comment

the AreaHelper.Areas is an Ienumerable that returns the names of the areas, and the tablet.Location is a table of locations, and the tablet.Location.Name is not null, its the name associated with locationID, I just want the locationId to be the value associated with each option

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.