简体   繁体   English

将下拉列表返回到最初选择的值

[英]Return dropdownlist to initially selected value

I'm creating a create-read-edit-delete interface. 我正在创建一个create-read-edit-delete接口。

I have a dynamically populated dropdownlist , ddl_Status which on page load is set to select a particular value. 我有一个动态填充的dropdownlistddl_Status ,它在页面加载时设置为选择一个特定的值。 The dropdownlist is then disabled. 然后禁用下拉列表。

If the user clicks "Edit" then I enable the dropdownlist. 如果用户单击“编辑”,则启用下拉列表。 The user can then change the selection. 然后,用户可以更改选择。

If the user clicks "Cancel" I want to return the dropdownlist to it's initial selection and then disable it. 如果用户单击“取消”,我想将下拉列表返回到它的初始选择,然后禁用它。 If I use ddl_Status.SelectedValue I get the value that the user has selected. 如果我使用ddl_Status.SelectedValue我会得到用户选择的值。

In javascript I would use ddl_Status.defaultValue but I can't find an equivalent in .NET. 在javascript中我会使用ddl_Status.defaultValue但我找不到.NET中的等价物。 I'm considering using a hidden field value to store the initial value, but this just seems clumsy. 我正在考虑使用隐藏字段值来存储初始值,但这看起来很笨拙。

填充下拉列表时,当用户单击“取消”时,将默认值存储在asp隐藏字段(hdn_DefaultValue)中:ddl_Status.selectedValue = hdn_DefaultValue。

You could store ddl_Status.SelectedIndex in a variable right after loading the page and restore it every time the user clicks "Cancel". 您可以在加载页面后立即将ddl_Status.SelectedIndex存储在变量中,并在每次用户单击“取消”时将其还原。 Of course this only works if there aren't any changes made to the items. 当然,只有在没有对项目进行任何更改的情况下,这才有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM