Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    TextBox e Button in Repeater

    Ho un campo testo e un bottone inseriti in un Repeater, ovviamente il campo testo e il bottone sono legati tra loro e all'id del prodotto:
    Nella Repeater1_ItemDataBound scrivo:
    codice:
     Dim bottone As Button = CType(e.Item.FindControl("button2"), Button)
                bottone.PostBackUrl = "Inserisci.aspx?id=" & DataBinder.Eval(e.Item.DataItem, "id")
    Così facendo riesco a fare il Redirect alla pagina inserisci.aspx e recuperare il valore dell'id del prodotto. La mia domanda è, come faccio a recuperare anche il valore della TextBox corrispondere al Bottone ed aggiungerlo alla QueryString?
    Vorrei passare anche la quantità tramie QueryString, altrimenti con il Request.Form si complica la questione.
    Spero di essere stato chiaro.

  2. #2
    Posto la soluzione che ho trovato da me(quindi suscettibile di miglioramenti) nel caso potesse servire a qualcuno:
    codice:
     Sub R1_ItemCommand(ByVal Sender As Object, ByVal e As RepeaterCommandEventArgs)
                If e.CommandName = "redirect" Then
                    Response.Redirect("InserisciNelCarrello.aspx?idprodotto=" & e.CommandArgument & "&quant=" & CType(e.Item.FindControl("quant"), TextBox).Text)
                End If
            End Sub
    
     Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) ' Handles Repeater1.ItemDataBound
                If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.EditItem Then
                     Dim bottone As Button = CType(e.Item.FindControl("button2"), Button)
                    bottone.CommandArgument = DataBinder.Eval(e.Item.DataItem, "idprodotto")
                End If
            End Sub
    codice:
                  <asp:Repeater id="Repeater1" OnItemCommand="R1_ItemCommand"  OnItemDataBound ="Repeater1_ItemDataBound" runat="server">
    
    <asp:Button ID="Button2" Text="Inserisci" CommandName="redirect" runat="server" />
    il tutto con AutoEventWireup="True"
    Spero di non aver dimenticato nulla.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.