Search code examples
asp.netvb.netrepeaterlinkbutton

ASP.NET: How can I find my other row elements from LinkButton click?


I have a Repeater with a LinkButton for each row. I want to be able to read the values of some other controls (such as a Label) that are in the same row as the LinkButton. Here is the code I'm currently using, but im not sure what to put in my "Click" method for the linkbutton to get the values of the other controls in my row.

Repeater ItemDataBound

Private Sub Repeater_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater.ItemDataBound

   Dim oRow As xsdTable.MyDataTableRow
   Dim RemoveLinkButton As LinkButton

   RemoveLinkButton = e.Item.FindControl("RemoveLinkButton")
   AddHandler RemoveLinkButton.Click, AddressOf RemoveLinkButton_Click

   // Set other Controls Information   

End Sub

RemoveLinkButton Click Event

Public Sub RemoveLinkButton_Click(sender As Object, e As System.EventArgs)

    // Not sure what to do here to get the id for that row and identify the other 
    // controls to get the information from them...

End Sub

Solution

  • You can use NamingContainer property of the control to get the RepeaterItem:

    Public Sub RemoveLinkButton_Click(sender As Object, e As System.EventArgs)
    
        Dim control = DirectCast(sender, Control)
        Dim item = DirectCast(control.NamingContainer, RepeaterItem)
        ' now use FindControl to get the other controls in this item '
    
    End Sub