One issue is that the repeater may have varying amounts of "sets."
Here's one way to handle it:
<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)
alert("Hotel name from repeater = " + $('#' + lblID).text())
MyLabel = document.getElementById(lblID)
alert("Hotel = " + MyLabel.innerText)
}
</script>
To populate the repeater, we can do 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
With this setup, you'll see something like this:
https://i.sstatic.net/CAoLw.png
When you click on a row, it triggers the JavaScript function and retrieves the corresponding hotel value.
For example:
https://i.sstatic.net/N5dO3.png
Even with only one set in the repeater, the index will start at 0, and each label will follow the naming convention:
"repeater name" + "_" + "label name" + "_" + row index