Btn.PostBackUrl / Nested with DropDownList INSIDE a Datalist



in VB.net 我有一个数据列表,其中我有一个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 才能看到),则回发工作正常。

它所做的(到目前为止)是获取DDLSubCat的第一个值(DDL的第一个索引)我需要以某种方式"刷新"(但不能)de DATABOUND或任何按钮工作正常的东西。

尝试了一切,做了ONCLICK(但是ddlSubCat没有出现在代码中,因为它在DL中)已尝试在"设计"视图中评估...但不能!

解决了!感谢 Tim Schmelter 的其他回答,我意识到我可以由 Codebehind 处理在 BTN 单击事件中,如下所示:

受保护的子BtnVerSubCat_Click(发送方作为对象,e 作为事件参数)

    Dim container = DirectCast(DirectCast(sender, Control).NamingContainer, DataListItem)
    Dim idSubCat = DirectCast(container.FindControl("ddlSubCat"), DropDownList)
    Dim Xid As String = idSubCat.SelectedValue
    Response.Redirect("SubCat.aspx?idSubCatgoria=" & Xid)
End Sub

无论如何谢谢

最新更新