Reference - adding an event to a dropdownlist in a repeater control - asp.net

M

mrwoopey

I did not find code for adding an event to dropdownlist in a repeater
control posted anywhere. So, I am posting it for the next person
(sorry if this seems obvious to you):

''''''''''''''''''''
Private Sub MyRepeater_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
MyRepeater.ItemCreated

Dim strValue As String
Dim objCTL As Control

For Each objCTL In e.Item.Controls
strValue = objCTL.GetType.ToString
If strValue = "System.Web.UI.WebControls.DropDownList"
Then
' 'add the click event and point to existing click
event
Dim objDDL As DropDownList = DirectCast(objCTL,
DropDownList)
AddHandler objDDL.SelectedIndexChanged, AddressOf
ddlINFO_SelectedIndexChanged
End If
Next

End Sub

Private Sub ddlINFO_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles ddlMapTarget.SelectedIndexChanged

'note make sure that ddlINFO has a autopostback="True" for for
this work

Dim objDDL As DropDownList = CType(sender, DropDownList)

lblMessage.Text = objDDL.SelectedValue()
lblMessage.Visible = True

End Sub
''''''''''''''

Phin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top