Btn.PostBackUrl /嵌套与DropDownList INSIDE一个Datalist

时间:2014-02-18 22:28:10

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

在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

我想要实现的是IF ddlSubCat的值已更改(导致某些用户 选择另一个SubCat看看POSTBACK正常工作。

它的功能(截至此处)是获取DDLSubCat的第一个值(DDL的第一个索引) 我需要一些“刷新”(但不能)de DATABOUND或其他适用于Button的工作正常。

尝试了一切,做了ONCLICK(但ddlSubCat在DL中没有出现在代码行中) 在设计视图中尝试EVAL ......但是不能!!

请提前帮助,请提供帮助

1 个答案:

答案 0 :(得分:0)

解决了! 感谢Tim Schmelter提出的其他答案,我认为我可以通过Codebehind处理 在这样的BTN点击事件中:

受保护的子BtnVerSubCat_Click(发件人为对象,e为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

非常感谢

相关问题