如何调用下拉列表选择在C#中的用户控件中更改事件 [英] How to call Drop down list selection Change event in User Contol in C#

查看:106
本文介绍了如何调用下拉列表选择在C#中的用户控件中更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是Chandra

我有一个查询。我有一个ASPX页面。在那我有一个下拉列表。此下拉列表正在执行某些操作。现在我有一个用户控件,它有一个单选按钮。我的问题是如何调用单选按钮列表选择更改事件中的下拉列表选择更改事件来执行相同的操作。

任何人都可以建议我查询以上内容。



谢谢

钱德拉

Hi,
This is Chandra
I have one query. I have an ASPX page. In that i have one drop down list. This Drop down list is performing some operations. Now i have an User Control which has one Radio button. My problem is how can i call Drop down list Selection change event in Radio Button List Selection Change event to perform same operations.
Can any one suggest me for the above query.

Thanks
Chandra

推荐答案

假设这是aspx页面中的DropDownList:

Suppose here is a DropDownList in aspx page:
<asp:dropdownlist id="ddlTest" runat="server">
   <asp:listitem>Food</asp:listitem>
   <asp:listitem>Clothes</asp:listitem>
</asp:dropdownlist>





现在从您的用户控件中,您将通过编写以下代码获得上述DropDownList:



Now from your user control you''ll get the above DropDownList by writing this following code:

DropDownList ddlTest = (DropDownList)this.Parent.FindControl("ddlTest");



现在你可以使用你的aspx页面中的DropDownList做任何事情。



我希望这会帮助。

谢谢。


Now you can do anything with this DropDownList which is in your aspx page.

I hope this will help.
Thanks.


我明白你必须在DropDownList选择更改事件和RadioButtonList选择cha上执行相同的代码块nge事件。如果是这样,请使用以下任一解决方案。



解决方案1:

移动代码从DropDownList事件到一个常用方法并从DropdownList和RadioButtonList选择改变事件调用此方法



解决方案2:

也为RadioButtonList使用DropDownList的selectedIndexChanged事件。这里也为Radiobuttonlist分配了事件名称DropDownList1_SelectedIndexChanged。



What I understood is you have to execute same code block on DropDownList selection change event and on RadioButtonList selection change event. If this is true, use either one of the following solutions.

Solution 1:
Move the code from DropDownList event to a common method and call this method from both DropdownList and RadioButtonList selection changed event

Solutions 2:
Use the selectedIndexChanged event of DropDownList for RadioButtonList also. Here the event name "DropDownList1_SelectedIndexChanged" assigned for Radiobuttonlist as well.

<asp:DropDownList ID="DropDownList1" runat="server"

           onselectedindexchanged="DropDownList1_SelectedIndexChanged">
           <asp:ListItem>Test1</asp:ListItem>
           <asp:ListItem>Test2</asp:ListItem>
       </asp:DropDownList>

       <asp:RadioButtonList ID="RadioButtonList1" runat="server"

           onselectedindexchanged="DropDownList1_SelectedIndexChanged">
           <asp:ListItem>test11</asp:ListItem>
           <asp:ListItem>Test22</asp:ListItem>
       </asp:RadioButtonList>


这篇关于如何调用下拉列表选择在C#中的用户控件中更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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