I'm working with a SelectList, and populating it with the data from a table. I'm trying to bind it to the ID of another object.
EDIT Updated the Schema to Reflect something I neglected. I have updated it to show the exact names of each item. I think the problem comes in the fact that each Unit has a sheet, and each sheet has a product. (The sheet will hold more information for the product, but a Unit will have a great deal of other information, so I wanted to separate them in order to keep it clear what was what.)
I think something is happening and the "Sheet" isn't being initialized as an object, and when the binding occurs, it doesn't have an object to bind to, since it is one-level deep. Tell me if this makes sense, or if I am just completely off base.
**Unit**
UnitID (PK)
**ProductSheet**
UnitId (FK)(PK)
ItemId (FK)
**Items**
ItemId (PK)
ItemTitle
It just ...isn't working though. I have this code.
DatabaseDataContext db = new DatabaseDataContext();
Unit unit = new Unit();
ViewData["Items"] = new SelectList( db.Items, "Id", "ItemTitle", unit.ProductSheet.ItemId);
But in the postback, the selectList is always null and empty! This is the View code. I'm really getting lost here, I've followed a lot of examples and it still comes up with bunk.
<%= Html.DropDownList("Items") %>