0

When working with ObjectDataSource I have following select:

<asp:DropDownList runat="server" SelectedValue='<%# Bind("InceptionCycle.ID") %>' ID="InceptionCycle" 
     DataSourceID="odsAllCycles" DataTextField="CycleName" DataValueField="ID" AppendDataBoundItems="true">
     <asp:ListItem Text="Choose..." Value=""></asp:ListItem>
</asp:DropDownList>

and ObjectDataSource configured with UpdateMethod and InsertMethod. However insert/update methods have parameters with InceptionCycle name (because InceptionCycle.ID is not valid identifier).

Is there a way to instruct ObjectDataSource to take InceptionCycle.ID form parameter and place in as InceptionCycle method parameter?

Here's full ObjectDataSource code:

<asp:ObjectDataSource ID="ods" runat="server" TypeName="Sources.DomainSource"
    SelectMethod="FindById" InsertMethod="Add" UpdateMethod="Update"
    OnInserted="ods_Inserted" OnUpdated="ods_Updated">
    <SelectParameters>
        <asp:QueryStringParameter Name="id" QueryStringField="id" />
    </SelectParameters>
    <InsertParameters>
        <asp:Parameter ConvertEmptyStringToNull="true" Name="ShortTitle" />
        <asp:Parameter ConvertEmptyStringToNull="true" Name="WMRId" />
        <asp:Parameter ConvertEmptyStringToNull="true" Name="MDSId" />
        <asp:Parameter ConvertEmptyStringToNull="true" Name="Status" />
    </InsertParameters>
    <UpdateParameters>
        <asp:QueryStringParameter Name="id" QueryStringField="id" />
        <asp:Parameter ConvertEmptyStringToNull="true" Name="ShortTitle" />
        <asp:Parameter ConvertEmptyStringToNull="true" Name="WMRId" />
        <asp:Parameter ConvertEmptyStringToNull="true" Name="MDSId" />
        <asp:Parameter ConvertEmptyStringToNull="true" Name="Status" />
    </UpdateParameters>
</asp:ObjectDataSource>
dragonfly
  • 17,407
  • 30
  • 110
  • 219

1 Answers1

0

You can only use the Bind syntax with a top level property - it doesn't support nested properties (VS 2012 will, though).

So, you should create a new property on your data source like below and bind the SelectedValue to this new property instead

 public string InceptionCycleID
 {
      get
      {
           return InceptionCycle.ID;
      }
      set
      {
           InceptionCycle.ID = value;
      }
 }
graham mendick
  • 1,839
  • 1
  • 17
  • 15
  • Actually, binding value to select control, it's not the issue and it wasn't stated in question. What is more, my SelectedValue is binded correctly when form loads. – dragonfly Jun 19 '12 at 12:50