Dropdown list bound to object data source - how to update on a button click

Posted by Jen on Stack Overflow See other posts from Stack Overflow or by Jen
Published on 2010-06-03T04:04:38Z Indexed on 2010/06/03 4:14 UTC
Read the original article Hit count: 181

Filed under:
|

This is probably something really stupidly simple..

I have a drop down list bound to an object data source. I have set AppendDataBoundItems to true so that I can have an initial select.

<asp:DropDownList ID="Accommodations1" runat="server" AutoPostBack="true" DataTextField="AccommodationTypeDescription" DataValueField="Id" OnDataBound="Accommodations1_DataBound" onSelectedIndexChanged="Accommodations1_SelectedIndexChanged" Width="200px" DataSourceID="AccommodationDs" AppendDataBoundItems="true">
       <asp:ListItem Text="Select" Value=""></asp:ListItem>
</asp:DropDownList>

<asp:ObjectDataSource ID="AccommodationDs" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="ListByPropertyId" TypeName="PropertyAccommodationController">
      <SelectParameters>
           <asp:Parameter Name="PropertyId" Type="Int32" />
      </SelectParameters>
</asp:ObjectDataSource>

I have a button which adds an accommodaton - so after that happens I need the dropdown list to update to include the new accommodation. So I've tried calling databind on the dropdownlist, and databind on the datasource - and nothing is making this dropdown list update.

eg. PropertyAccommodations1.DataBind();

Could someone please let me know what I'm doing wrong. Originally I thought it was due to an update panel issue.. but I've removed the update panel and it still doesn't work (and checked the master page doesn't include an update panel).

Thanks!!

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-3.5