Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

281
Vistas
How to want to get label value inside the repeater control in JavaScript variable

I want to get label value inside the repeater control in JavaScript variable

<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>

My Code Is

var valComments =document.getElementById('<%=rlbl_Remarks.ClientID%>').innerText;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Well, the problem is the repeater might have 1 or 15 "sets"

So, you can do it like this:

        <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>

So, in above, we might fill the repeater like this:

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

And then we now have this:

enter image description here

When we click on the row click, it calls the js, and gets the one hotel value.

eg:

enter image description here

so, even if you have only 1 set in the repeater, it will start at 0 for the index, and each label will have a name of

"repeater name" + "_" + "label name" + "_" + row index
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda