绑定到对象数据源下拉列表 - 如何在点击一个按钮更新 [英] Dropdown list bound to object data source - how to update on a button click

查看:180
本文介绍了绑定到对象数据源下拉列表 - 如何在点击一个按钮更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是可能的东西真的太简单..

This is probably something really stupidly simple..

我有一个下拉绑定到一个对象数据源列表。我已经设置AppendDataBoundItems为true,这样我可以有一个初步的选择。

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>



我有一个按钮,增加了一个accommodaton - 所以出现这种情况后,我需要的下拉列表更新到包括新的住处。所以,我试着打电话数据绑定在DropDownList的,并在数据源数据绑定 - 并没有什么使这个下拉列表更新

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.

如。 PropertyAccommodations1.DataBind();

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 for the quick responses - have implemented

Accommodations1.Items.Insert(0,new ListItem("Select","")); 



我特别想让它在顶部:)

as I specifically wanted it at the top :)

我仍然认为这将是整洁有在页面的源代码这种默认的项目 - 但AppendDataItems被绊倒了我。

I still think it would be neater to have this default item in the source of the page - but that AppendDataItems is tripping me up.

这篇关于绑定到对象数据源下拉列表 - 如何在点击一个按钮更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆