如何获得的DropDownList的previous项目之前OnSelectedIndexChanged触发事件 [英] How to get the previous item on DropDownList before OnSelectedIndexChanged fires the event

查看:129
本文介绍了如何获得的DropDownList的previous项目之前OnSelectedIndexChanged触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何前 OnSelectedIndexChanged 获得的DropDownList 的previous项目引发事件?

How would I get the previous item on DropDownList before OnSelectedIndexChanged fires the event?

例子:我有一个的DropDownList 有名称作为其项目(约翰福音,马)。默认情况下,的SelectedIndex 是约翰。一旦改变其索引,然后选择标记事件 OnSelectedIndexChanged 将被触发。当我使用 ddlName.SelectedIndex 将用于马克,我希望得到的是约翰的索引只返回指数。

Example: I had a DropDownList that has names as its items ("John", "Mark"). By default the SelectedIndex is "John". Upon changing its index and selecting "Mark" the event OnSelectedIndexChanged will be triggered. When I use ddlName.SelectedIndex it will return only the index for "Mark" which I want to get is the index of "John".

推荐答案

您不能捕获事件之前的变化,但是你可以很容易地存储在一个变量previous值。每一次的SelectedIndexChanged被激发,使用previous值,然后将其设置为新指数(下一次的事件触发的)。为了处理这种情况时,它是一个新的选择(从默认的),你可以设置变量在页面加载时,或者允许它为空,并有提醒用户注意的事实,这是一个新的选择(然后你​​就可以处理但是你喜欢)。

You can't capture an event prior to the change, but you could easily store the previous value in a variable. Each time SelectedIndexChanged is fired, use the previous value and then set it to the new index (for the next time the event fires). To handle the case when it's a new selection (from the default), you can either set the variable when the page loads, or allow it to be null and have that alert you to the fact it's a new selection (which you can then handle however you like).

这篇关于如何获得的DropDownList的previous项目之前OnSelectedIndexChanged触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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