【问题标题】:Btn.PostBackUrl / Nested with DropDownList INSIDE a DatalistBtn.PostBackUrl / 与 DropDownList 嵌套在 Datalist 内
【发布时间】:2014-02-18 22:28:09
【问题描述】:

在 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 没有出现在 codebehing 中,因为它在 DL 中) 尝试在设计视图中进行 EVAL...但不能!

【问题讨论】:

    标签: vb.net button command-line-arguments dropdownlistfor datalistitem


    【解决方案1】:

    已解决! 感谢 Tim Schmelter 的其他回答,我意识到我可以由 Codebehind 处理 在像这样的 BTN 点击事件中:

    Protected Sub BtnVerSubCat_Click(sender As Object, e As EventArgs)

        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
    

    还是谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-20
      • 2016-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多