Marcin
I think i've figuured out the cascading drop downs, I'd appreciate input on any improvements you can think of. I used a custom Field Template with 2 linq to sql data sources, source for the control is below.
ASCX file
<asp:LinqDataSource ID="lqsManufacturers" runat="server"
ContextTypeName="AssetRegisterDataContext"
TableName="Manufacturers" OrderBy="manufacturer_name">
</asp:LinqDataSource>
<asp:LinqDataSource ID="lqsModels" runat="server"
ContextTypeName="AssetRegisterDataContext" TableName="Models"
Where="manufacturer_id == @manufacturer_id">
<WhereParameters>
<asp:ControlParameter ControlID="manufacturersDropDown" Name="manufacturer_id"
PropertyName="SelectedValue" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
<asp:Label runat="server" Text="Manufacturer" />
<asp:DropDownList ID="manufacturersDropDown" runat="server"
DataSourceID="lqsManufacturers" DataTextField="manufacturer_name"
DataValueField="manufacturer_id" AutoPostBack="true" />
<br />
<asp:Label runat="server" Text="Model" />
<asp:DropDownList ID="modelsDropDown" runat="server"
DataSourceID="lqsModels" DataTextField="model_name"
DataValueField="model_id" />
Code behind .cs
1 public partial class DynamicData_FieldTemplates_ManufacturerModel : System.Web.DynamicData.FieldTemplateUserControl
2 {
3 // Set up the original values.
4 protected override void OnDataBinding(EventArgs e)
5 {
6 base.OnDataBinding(e);
7 object val = FieldValue;
8
9 // Get the manufactuer_id for the current model
10 AssetRegisterDataContext db = new AssetRegisterDataContext();
11 var models = from mo in db.Models
12 where mo.model_id == (int)val
13 select mo.Manufacturer.manufacturer_id;
14
15 // Set the Manufacturer drop down to the value from the model record.
16 manufacturersDropDown.SelectedValue = models.Single().ToString();
17 // Now set the Model drop down to the value from the database.
18 modelsDropDown.SelectedValue = val.ToString();
19 }
20 protected override void ExtractValues(IOrderedDictionary dictionary)
21 {
22 dictionary[Column.Name] = modelsDropDown.SelectedValue;
23 }
24 public override Control DataControl
25 {
26 get
27 {
28 return modelsDropDown;
29 }
30 }
31 }