asp.net - aspx dropdownList 不维护所选值
问题描述
带有下拉列表的继承代码,用于填充一些 GridView。在下拉列表中进行选择时,选择不会保留,它会跳回到第一条记录。经常提到的修复方法是在 Page_Load 事件中添加 !Page.IsPostBack,但是这样做并不能解决问题。
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true"
DataSourceID="SqlDataSource2" DataTextField="FullAddress"
DataValueField="UniqueRecordID" Width="445px" Height="20px"
style="margin-left: 0px" TabIndex="8" AppendDataBoundItems="true"
OnSelectedIndexChanged="resetGridsAndLabel">
</asp:DropDownList>
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList2.DataSource = sqlDataSource2;
DropDownList2.DataBind();
}
解决方案
您是否在页面的其他任何位置设置 DDL 的数据源?
推荐阅读
- python - 将 excel 文件上传到 PostgreSQL 中的表
- java - 在 gradle 中排除声纳类
- javascript - React Hook useEffect 缺少依赖项:'props' 由于 useEffect 中有一行
- r - 表中的错误,找不到对象 R 降价
- javascript - 切换功能后激活悬停颜色
- reactjs - 如何放大 react-simple-maps 中的特定地理位置?
- pandas - Pandas 在数据集中寻找振荡
- xslt - 如何让 XSLT 键功能适用于我的场景?
- python - Keras:如何在另一个模型中正确匹配模型的形状
- visual-studio - Visual Studio 2019 中多行编辑的键盘绑定丢失