in VB.net I have a DATALIST in which, among others I have a DropDL CTRL which is Bound with LINQ something like this:
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
What I am trying to achieve is that IF ddlSubCat has its value changed (cause some user selected another SubCat to see) the POSTBACK get working fine.
What it does (up to here) is getting the FIRST value of DDLSubCat (first index of DDL) I need to SOMEHOW "refresh" (but can't) de DATABOUND or whatever for the Button Works fine.
Tried everything, did ONCLICK (but the ddlSubCat does not appear in codebehing since its in DL) Tried to EVAL in Design view... BUT CAN'T!
SOLVED ! Thanks to som other answer from Tim Schmelter, I realice that I could be handled by Codebehind in the BTN click event like this:
Protected Sub BtnVerSubCat_Click(sender As Object, e As EventArgs)
Thanks anyway