简体   繁体   中英

Return dropdownlist to initially selected value

I'm creating a create-read-edit-delete interface.

I have a dynamically populated dropdownlist , ddl_Status which on page load is set to select a particular value. 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.

In javascript I would use ddl_Status.defaultValue but I can't find an equivalent in .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". Of course this only works if there aren't any changes made to the items.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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