This is the error that I get: 'ddlEye_SelectedIndexChanged' is not a member of 'ASP.controls_claims_laborder_ascx'.
The reason is that your event handler is Private
. You either need to make it Protected
or Public
or you can't add the event-handler declaratively on the ascx but you need to add it programmatically in codebehind (by using Handles
or AddHandler
).
So for example:
Protected Sub ddlEye_SelectedIndexChanged(sender As Object, e As System.EventArgs)
' ...
End Sub
or (note the Handles
)
Private Sub ddlEye_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlEye.SelectedIndexChanged
' ...
End Sub
Here you need to remove following from ascx
OnSelectedIndexChanged="ddlEye_SelectedIndexChanged"
Side-note: you use
AddHandler dlEye.SelectedIndexChanged, AddressOf ddlEye_SelectedIndexChanged
in VB.NET.
Update
Thank you so much it worked. Perhaps you can help me with another issue, I want to get the textbox value in the same row as the DropDownList when setectedIndex changes?
You can get the RepeaterItem
via NamingContainer
, you just need to cast it accordingly. Then you can use FindControl("ID")
to get the TextBox
:
Protected Sub ddlEye_SelectedIndexChanged(sender As Object, e As System.EventArgs)
Dim dEye As DropDownList = DirectCast(sender, DropDownList)
Dim item = DirectCast(dEye.NamingContainer, RepeaterItem)
Dim txtTariff = DirectCast(item.FindControl("txtTariff"), TextBox)
' ...
End Sub