在下拉列表中选择时,所选项目不会更改 [英] Selected Item not changing when selected on drop down list

查看:72
本文介绍了在下拉列表中选择时,所选项目不会更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我通过使其等于数据库中的值来在下拉列表中选择一个项目,但是,当用户去选择一个新项目然后按更新"按钮时,仍然显示旧值.

如何更改值,然后更改项目?

我的代码如下:

Hi all,

I am selecting an item in a drop down list by making it equal to the value in a database, however, when the user goes to select a new item and then press the update button, the old value is still displayed.

How can I make it so that once the value is changed, the item is changed?

The code I have is as follows:

dropdownlist1.SelectedIndex = dropdownlist1.Items.IndexOf(dropdownlist1.Items.FindByValue(query.Status));



查询"是LINQ查询.



"query" is a LINQ query.

推荐答案

好吧,您正在做的事情看起来很正确-取决于它在页面生命周期中何时发生- ASP.NET页面生命周期 [
Well, what you are doing looks right - depending on when it''s happening during the page lifecycle - ASP.NET Page Life Cycle[^].

You also have to make sure that there are items in the dropdownlist1 before setting SelectedIndex - if the control is bound, this has to happen after binding has completed and not on postbacks.

Best regards
Espen Harlinn


检查下拉列表属性是否为autopostback = true;
并使用page_load编码使用
if(!page.Ispostback == true)
{
//更改下拉列表的选定索引值..
}
check whether dropdown list properties is autopostback=true;
and using page_load coding use
if(!page.Ispostback==true)
{
//change dropdownlist selectedindex value..
}


plz确认您已使autopostback == true
plz confirm that you have made autopostback==true


这篇关于在下拉列表中选择时,所选项目不会更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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