Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

279
Views
Cómo querer obtener el valor de la etiqueta dentro del control repetidor en la variable JavaScript

Quiero obtener el valor de la etiqueta dentro del control repetidor en la variable JavaScript

 <asp:Repeater ID="rep_tskAttachments" runat="server" OnItemDataBound="rep_tskAttachments_ItemDataBound"> <asp:Label ID="rlbl_Remarks" runat="server" Text='<%# Eval("REMARKS") %>'></asp:Label> </asp:Repeater>

mi codigo es

 var valComments =document.getElementById('<%=rlbl_Remarks.ClientID%>').innerText;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Bueno, el problema es que el repetidor puede tener 1 o 15 "conjuntos"

Entonces, puedes hacerlo así:

 <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <asp:Label ID="lblHotel" runat="server" width="200px" Text='<%# Eval("HotelName") %>' > </asp:Label> <asp:Button ID="Button1" runat="server" Text="Row click (client side)" OnClientClick='<%# "myrowfun(" + Container.ItemIndex.ToString + ");return false;" %>' /> <br /> </ItemTemplate> </asp:Repeater> <script> function myrowfun(ix) { alert("row click index = " + ix) lblID = "Repeater1_lblHotel_" + ix alert(lblID) // jQuery alert("Hotel name from repeater = " + $('#' + lblID).text()) // javascript without jQuery MyLabel = document.getElementById(lblID) alert("Hotel = " + MyLabel.innerText) } </script>

Entonces, arriba, podríamos llenar el repetidor así:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then LoadGrid() End If End Sub Sub LoadGrid() Using con As New SqlConnection(My.Settings.TEST3) Using cmdSQL = New SqlCommand("SELECT TOP 5 ID, FirstName, LastName, HotelName from tblHotels ORDER BY HotelName", con) con.Open() Repeater1.DataSource = cmdSQL.ExecuteReader Repeater1.DataBind() End Using End Using End Sub

Y ahora tenemos esto:

ingrese la descripción de la imagen aquí

Cuando hacemos clic en la fila, llama al js y obtiene el valor de un hotel.

p.ej:

ingrese la descripción de la imagen aquí

por lo tanto, incluso si solo tiene 1 conjunto en el repetidor, comenzará en 0 para el índice, y cada etiqueta tendrá un nombre de

 "repeater name" + "_" + "label name" + "_" + row index
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!