且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在动态创建的下拉列表中添加值

更新时间:2023-12-01 09:56:34

参考 - 保留动态创建控件的状态ASP.NET应用程序 [ ^ ]。

Refer - Retaining State for Dynamically Created Controls in ASP.NET applications[^].
引用:

当动态地向ASP.NET添加控件时在运行时页面中,对象引用在回发时丢失,因为它们在代码隐藏中没有句柄。在回发后访问这些对象时,用户输入的值不可用,并且它们看起来是空的。本文介绍如何使用ViewState重新创建并将回发值重新插入到对象中以访问其值。

When dynamically adding controls to an ASP.NET page in runtime the object references are lost at postback because they have no handle in the codebehind. The values entered by the user is not availible when accessing these objects after postback, and they seem empty. This article describes how to use ViewState to recreate and reinsert the postback values into the objects to access their values.

您必须在每个Post Post中重新创建控件。

You have to recreate the controls in each Post Back.