I have a repeater with a dropdownlist in it. When a user changes its index, I would like a label to change its value. (the ddlSizes values come from a MySQL DB)
Sizes.aspx
<asp:DropDownList ID="ddlSizes" runat="server" AutoPostBack="True" DataSourceID="objdsSizes" DataTextField="SizeName" DataValueField="SizeID" />
<asp:Label ID="lbldummy" runat="server" Text=""></asp:Label>
Sizes.aspx.vb
Protected Sub ddlSizes_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSizes.SelectedIndexChanged
lbldummy = ddlSizes.value
End Sub
But the ddlSizes.SelectedIndexChanged isn't recognized. So the value of lbldummy
won't change.
Any suggestions? Thank you.
Here's an example (C# but easily adaptable to VB.NET). Notice how inside the
DdlSizes_SelectedIndexChanged
I useFindControl
to find the corresponding label:You will want to create the handler for the
DropDownList
, within this you need to have code which will convert the sender into aDropDownList
then get the parent control and convert it into theRepeaterItem
. From this you can then reference any other controls within theRepeaterItem
Then on your ddlSizes DropDownList add
OnSelectedIndexChanged="ddlSizes_SelectedIndexChanged"
and make sure it has AutoPostBack="True" setText is probably the default property, but I'd still specify it:
lbldummy.Text = ddlSizes.value
but for this, you really don't need to do a postback, you can accomplish this through Javascript as well. doing something like this: