C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

Handling SelectedIndexChanged event in DropDownList


Posted Date: 05 Dec 2005    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: Kuljit Singh SainiMember Level: Bronze    
Rating: 1 out of 5Points: 3



The code sample explains a way to handle a SelectedIndexChanged event in a DropDownList control

Steps to handle such events are listed below :

- Select AutoPostBack=true for DropDownList
- Specify function to call in OnSelectedIndexChanged="DropDownListSelect"
- Create the Public Function specified above
- Public Sub DropDownListSelect(ByVal sender As Object, ByVal e As System.EventArgs)
- get sender.Parent.anycontrol to manipulate

Example code follows:

The code immediately below is the .aspx page that displays a DropDownList control on a web page.

<ItemTemplate>

<asp:DropDownList ID="ddl1" Runat=server
AutoPostBack=True OnSelectedIndexChanged="DropDownListSelect">
</asp:DropDownList>
<asp:Label ID="lblStatus" Runat=server></asp:Label>

</ItemTemplate>


The sample code below shows VB.NET code that actually does the event handling.
When the event occurs, the page just displays a Hello in a Label control.


Public Sub DropDownListSelect(ByVal sender As Object, ByVal e As System.EventArgs)
Dim oDropDownList As DropDownList
Dim oLabel As Label
oDropDownList = CType(sender, DropDownList)
oLabel = oDropDownList.Parent.FindControl("lblStatus")
oLabel.Text = "Hello"
End Sub






Responses

Author: sreenu    19 Sep 2006Member Level: Bronze   Points : 0
Thank you for sharing the info..


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
SelectedIndexChanged event  .  Handling SelectedIndexChanged event for DropDownList control  .  Handling SelectedIndexChanged event  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: MVC design pattern using ASP.NET
Previous Resource: A better way of working with IE Webcontrols - Part II
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use