[英]List Item Selected property not firing click event handler
I have two dropdown lists, ddlPrimarySeries
and ddlSecondarySeries
. 我有两个下拉列表,
ddlPrimarySeries
和ddlSecondarySeries
。 I also have a button ( ImgBtnSeriesReversal
) in the middle of these dropdown lists that switches the selected values in the dropdown. 这些下拉列表的中间还有一个按钮(
ImgBtnSeriesReversal
),用于切换下拉列表中的选定值。 This is the code that switches the selected items on the button click: 这是在单击按钮时切换所选项目的代码:
foreach (ListItem item in ddlPrimarySeries.Items)
{
if (Convert.ToInt32(item.Value) == intSecondarySeries)
{
item.Selected = true;
break;
}
}
foreach (ListItem item in ddlSecondarySeries.Items)
{
if (Convert.ToInt32(item.Value) == intPrimarySeries)
{
item.Selected = true;
break;
}
}
It loops through the list items and sees if the currently iterated item is equal to the selected item in the other dropdown and if so it selects it with item.Selected = true
and then breaks. 它循环遍历列表项,并查看当前迭代的项是否与另一个下拉列表中的选定项相等,如果是,则使用
item.Selected = true
选择它,然后中断。 My issue is that when the values switch in the dropdowns the ddlPrimarySeries_SelectedIndexChanged
and ddlSecondarySeries_SelectedIndexChanged
events don't get fired. 我的问题是,当在下拉列表中切换值时,不会触发
ddlPrimarySeries_SelectedIndexChanged
和ddlSecondarySeries_SelectedIndexChanged
事件。 How can I accomplish this and have the event handlers fire when the values change? 当值更改时,我该如何完成并让事件处理程序触发?
foreach (ListItem item in ddlPrimarySeries.Items)
{
if (Convert.ToInt32(item.Value) == intSecondarySeries)
{
item.Selected = true;
break;
}
}
***ddlPrimarySeries_SelectedIndexChanged(new object(), new EventArgs());***
foreach (ListItem item in ddlSecondarySeries.Items)
{
if (Convert.ToInt32(item.Value) == intPrimarySeries)
{
item.Selected = true;
break;
}
}
***ddlSecondarySeries_SelectedIndexChanged(new object(), new EventArgs());***
Check that you have AutoPostBack set to true for the dropdown lists. 检查下拉列表的AutoPostBack是否设置为true。 By default it is false.
默认情况下为false。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.