DROPDOWNLIST在一个中继器,选择指数变化不工作 [英] Dropdownlist in a repeater, selected index changed not working

查看:157
本文介绍了DROPDOWNLIST在一个中继器,选择指数变化不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它一个DropDownList中继器。当用户更改其索引,我想一个标签来改变其值。 (来自MySQL数据库的ddlSizes值)

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

但ddlSizes.SelectedIndexChanged无法识别。因此, lbldummy 的价值不会改变。

有什么建议?谢谢你。

推荐答案

您要创建处理程序的的DropDownList ,在此,你需要有$ C $ ç将发送转换成的DropDownList 然后获取父控件,并将其转换成的RepeaterItem 。从这你就可以参考中的任何其他控件的RepeaterItem

You will want to create the handler for the DropDownList, within this you need to have code which will convert the sender into a DropDownList then get the parent control and convert it into the RepeaterItem. From this you can then reference any other controls within the RepeaterItem

Public Sub ddlSizes_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim ddlSizes As DropDownList = DirectCast(sender, DropDownList)
    Dim ri As RepeaterItem = DirectCast(ddlSizes.Parent, RepeaterItem)
    Dim lbldummy As Label = DirectCast(ri.FindControl("lbldummy"), Label)
    lbldummy.Text = ddlSizes.SelectedValue
End Sub

然后在你的ddlSizes DROPDOWNLIST添加 OnSelectedIndexChanged =ddlSizes_SelectedIndexChanged,并确保它的AutoPostBack =真设置

Then on your ddlSizes DropDownList add OnSelectedIndexChanged="ddlSizes_SelectedIndexChanged" and make sure it has AutoPostBack="True" set

这篇关于DROPDOWNLIST在一个中继器,选择指数变化不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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