如何获取自定义下拉框选项改变事件
后台加载事件中调用‘创建填充属性值的控件’
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
CreateAttrValueList()
End Sub
‘创建填充属性值的控件’代码如下:
Public Sub CreateAttrValueList()
Dim dr As DataRowCollection = GetAttrName(PID)'获取商品属性名
Dim ids As String = ""
Dim i As Integer
For i = 0 To dr.Count - 1
Dim ddlAttr As DropDownList = New DropDownList()
ddlAttr.ID = "ddl" & dr(i)("ID")
ids += ddlAttr.ID & "," '拼接id集合
Dim dr2 As DataRowCollection =GetAttrValue(PID,dr(i)("ID"))'获取商品属性值
Dim j As Integer
For j = 0 To dr2.Count - 1
ddlAttr.Items.Add(New ListItem(dr2(j)("AttrValueCn"), dr2(j)("ID")))
Next
Me.plAttrList.Controls.Add(attrName)
Me.plAttrList.Controls.Add(ddlAttr)
Next
End Sub
以上功能效果已实现,现在我想在改变任意一个下拉框时,根据下拉框的值查询信息。
各位大虾,怎么获取这种自动创建下拉框的选项改变事件?或者还有没有其它解决方案,麻烦贴出来。先谢啦!~
------解决方案--------------------
ddlAttr.AutoPostBack = True
AddHandler ddlAttr.SelectedIndexChanged, AddressOf OnSelectedIndexChanged
Protected Sub OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim ddl As DropDownList = DirectCast(sender, DropDownList)
Dim ID As String = ddl.ID
'Place the functionality here
ClientScript.RegisterClientScriptBlock(Me.GetType(), _
"Alert", "<script type = 'text/javascript'>alert('" & ID _
& " fired SelectedIndexChanged event');</script>")
End Sub