在 VB.net 中,我有一个 DATALIST,其中我有一个 DropDL CTRL,它与 LINQ 绑定,如下所示:
Public Sub DLCategorias_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DLCategorias.ItemDataBound
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
Dim DC As New MyDataContext
Dim cat = (From c In FF.ProductosCategorias Select c Where c.idCategoria = (CTypeDLCategorias.DataKeys(e.Item.ItemIndex), Integer))).Single
Dim thisId As Integer = cat.idCategoria
Dim subcat = From d In dc.ProductosSubCategorias Where d.idCategoria = thisId Select d.idSubCategoria, d.NombreSubCategoria
Dim ddlSubCat As DropDownList = CType(e.Item.FindControl("ddlSubCat"), DropDownList)
Dim BTNVER As Button = CType(e.Item.FindControl("BtnVerSubCat"), Button)
ddlSubCat.DataTextField = "NombreSubCategoria"
ddlSubCat.DataValueField = "idSubCategoria"
ddlSubCat.DataSource = subcat
ddlSubCat.DataBind()
ddlSubCat.AutoPostBack = True
BTNVER.PostBackUrl = "SubCat.aspx?idSubCategoria=" & ddlSubCat.SelectedValue.ToString
我想要实现的是,如果 ddlSubCat 的值发生了变化(导致某些用户选择了另一个 SubCat 来查看),则 POSTBACK 可以正常工作。
它所做的(到这里)是获取 DDLSubCat 的第一个值(DDL 的第一个索引)我需要以某种方式“刷新”(但不能)de DATABOUND 或任何按钮都可以正常工作。
尝试了一切,ONCLICK(但 ddlSubCat 没有出现在代码行为中,因为它在 DL 中)尝试在设计视图中 EVAL...但不能!