onSelectedIndexChanged

onSelectedIndexChanged

本文介绍了如何编写OnSelectedIndexChanged事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,





我很困惑,如何写一个下拉列表的OnSelectedIndexChanged事件。



Hi guys,


I'm very confused, how to write OnSelectedIndexChanged Event of a dropdownlist.

SCENARIO:

---------------------------------------------------------------------------
|Repeater 1                                                                |
---------------------------------------------------------------------------
| ------------------------------------------------------------------------ |
| |Repeater 2                                                             ||
| |-----------------------------------------------------------------------||
| |-----------------------------------------------------------------------||
| |WEB USER CONTROL WITH: DROPDOWNLIST N A TEXTBOX  - [1]                 ||
| |-----------------------------------------------------------------------||
| |WEB USER CONTROL WITH: DROPDOWNLIST N A TEXTBOX  - [2]                 ||
| |-----------------------------------------------------------------------||
| |WEB USER CONTROL WITH: DROPDOWNLIST N A TEXTBOX  - [3]                 ||
| |-----------------------------------------------------------------------||
| -------------------------------------------------------------------------|
----------------------------------------------------------------------------





我已经填充了d下拉列表,它位于WebUserControl中,

但是,现在问题是,

如何编写OnSelectedIndexChanged事件。

所以,如果我在d下拉列表中选择任何值,它的文本也应该出现在那个WebUserControl的文本框中。



Plzzzz的家伙帮帮我。





谢谢



I have populated d dropdownlist which is in d WebUserControl,
but, now the problem is,
How to write its "OnSelectedIndexChanged" event.
So that, If i select any value in d dropdownlist, its text should also appear in
the textbox of that WebUserControl.

Plzzzz guys help me.


thanks

推荐答案


public event Action<string>OnSelectedIndexChangedDropDownListEvent;



此事件可以由使用您的Web用户控件的页面订阅。

在Web用户中你在写OnSelectedIndexChanged的方法中控制:




This event can be subscribed to by the pages that uses your web user control.
in the web user control in the method for the OnSelectedIndexChanged you write:

if (OnSelectedIndexChangedDropDownListEvent!=null)
    OnSelectedIndexChangedDropDownListEvent(dropdownListNameHere.SelectedValue);



所以内部事件是通过OnSelectedIndexChangedDropDownListEvent发布到外部世界。


So the inner event is posted to the outside world via the OnSelectedIndexChangedDropDownListEvent.


protected void rptrSection1_Bound(object sender, RepeaterItemEventArgs e)
{
var ctl = e.Item.FindControl("ddlS1") as SDropDownList;
ctl.SelectedIndexChanged += new EventHandler(ddlS1_SelectedIndexChanged);
}

[code]....


这篇关于如何编写OnSelectedIndexChanged事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 12:56