选定的索引事件未触发 [英] Selected Index event not firing

查看:49
本文介绍了选定的索引事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单上有一个下拉组合框,我将其AutoPostBack属性

设置为true。当我从列表中选择一些内容时它会进行回发和

然后会引发Page_Load事件,然后是它的SelectedIndexChanged事件。


然而,当我再次返回此控件并选择

列表中的第一项,它会进行回发并触发Page_Load事件,但

SelectedIndexChanged不会触发。为什么在选择列表中的第一项时,SelectedIndexChanged会跳过




总之,我有一个下拉列表。我选择列表中的第3项并且

,SelectedIndexChanged会像它应该的那样触发。当我单步执行代码时我会看到所选索引= 2.现在当我回去并选择

中的第一项时,列表并逐步执行代码我可以看到所选索引= 0(从2更改

),但是SelectedIndexChanged没有触发。


如何解决这个问题?


谢谢。


-
mo*******@nospam.com

I have a dropdown combo box on a form and I have its AutoPostBack property
set to true. When I select something from the list it does a postback and
then the Page_Load event fires followed by it''s SelectedIndexChanged event.

However, when I go back to this control again and select the first item in
the list, it does a postback and the Page_Load event fires, but the
SelectedIndexChanged doesn''t fire. Why does the SelectedIndexChanged get
skipped when selecting the first item in the list?

In summary, I have a dropdown list. I select the 3rd item in the list and
the SelectedIndexChanged fires like it should. As I step through the code I
see the selected index = 2. Now when I go back and select the first item in
the list and step through the code I can see the selected index =0 (changed
from 2), but the SelectedIndexChanged doesn''t fire.

How can I resolve this?

Thanks.

--
mo*******@nospam.com

推荐答案

确保在IntializeComponent中定义(实例化)事件< br $>
程序。

-

Peter O''Reilly
Make sure the event is defined (instantiated) in the IntializeComponent
procedure.
--
Peter O''Reilly


你能给吗?我是一个如何做到这一点的例子? (vb.net,如果你可以....)

它不在IntializeComponent中,它只是这样声明:


受保护的WithEvents cmbShipMethod As System。 Web.UI.WebControls.DropDownList

谢谢。


-
mo ******* @ nospam.com

" Peter O''Reilly" < Pe的*********** @ timeinc.com N 2 O 2 .S P AM>!!;!在消息中写道

news:ee ************* @ TK2MSFTNGP09.phx.gbl ...
Can you give me an example of how I would do that? (vb.net if you can....)
Its not in the IntializeComponent and its simply declared like this:

Protected WithEvents cmbShipMethod As System.Web.UI.WebControls.DropDownList
Thanks.

--
mo*******@nospam.com
"Peter O''Reilly" <Pe***********@timeinc.com!N!O!.S!P!AM!> wrote in message
news:ee*************@TK2MSFTNGP09.phx.gbl...
确保定义了事件(实例化)IntializeComponent
程序。
-
Peter O''Reilly
Make sure the event is defined (instantiated) in the IntializeComponent
procedure.
--
Peter O''Reilly



您好,


根据您的描述,我构建了一个简单的测试Web表单。但是,我没有找到你提到的问题
。我只需添加一些代码

DropDownList1_SelectedIndexChanged:


Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,

ByVal e As System。 EventArgs)处理DropDownList1.SelectedIndexChanged

Response.Write(" changed")

End Sub


并在这条线。运行应用程序后,每当我在下拉列表控件中选择一个项目时,断点

就会停止。


你能发布一些代码来澄清问题?也许我们可以从中获得更多详细信息。


Luke

Microsoft在线支持


安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)
Hello,

Based on your description, I build a simple test web form. However, I
haven''t found the problem you mentioned. I just add some code in
DropDownList1_SelectedIndexChanged:

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Response.Write("changed")
End Sub

And add a breakpoint at the line. After run the application, the breakpoint
get stopped whenever I select a item in the dropdown list control.

Can you post some of your code to clarify the problem? Maybe we can get
more detail informaiton from that.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


这篇关于选定的索引事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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