Getting the clicked Row value of a nested repeater

Hi All:

Here's my repeater:

<asp:repeater id="rptDivision" runat="server">
                  <%# DataBinder.Eval(Container.DataItem, "DivisionDesc")%>
            <asp:repeater id="rptActivity" runat="server" OnItemCommand="GetActivityToEdit_ItemCommand" DataSource='<%# ActivityDataBind(DataBinder.Eval(Container.DataItem,"DivisionID")) %>'>
                        <ASP:Button ID="lblActivityID" Text='<%# DataBinder.Eval(Container.DataItem, "ActivityID") %>' runat="server">
                        <%# DataBinder.Eval(Container.DataItem, "ActivityName")%>
            </asp:repeater><BR />

I need the value of lblActivityID for whatever button they press. I don't HAVE to use the button though.. I'd really prefer a hyperlink or a LinkButton. I tried to play with GetActivityToEdit_ItemCommand, but that doesn't work well for a nested repeater.. that and I don't know how to make it work. heh.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

in rptDivision:]

Sub Item_Created(ByVal sender As Object, ByVal e As DataListItemEventArgs)
   Dim neededLabel As Label = CType(e.Item.FindControl("lblActivityID"), Label)
End Sub
Mitchell_Author Commented:

I get this error:

Compiler Error Message: BC30408: Method 'Public Sub Item_Created(sender As Object, e As System.Web.UI.WebControls.DataListItemEventArgs)' does not have the same signature as delegate 'Delegate Sub RepeaterItemEventHandler(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs)'.

in the Sub that you gave me, it says "DataListItemEventArgs" - should that be that way for a repeater?

I am also not sure I see how it will give me the value of the clicked button ..

Sample Working Code :

'HTML Page Code:

<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="">
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
      <asp:Repeater id="Repeater1" runat="server">
            <table border="1">
            <tr bgcolor="#ffcc99">
            <th>First Name</th>
            <th>Last Name</th>
            <tr bgcolor="#ffcccc">
            <td><asp:Button CommandName="ID" Text=<%# DataBinder.Eval(Container.DataItem, "au_id") %>
                                    runat=server ID="Button1"/></td>

            <td><%# DataBinder.Eval(Container.DataItem, "au_fname") %></td>
            <td><%# DataBinder.Eval(Container.DataItem, "au_lname") %></td>
            <td><%# DataBinder.Eval(Container.DataItem, "address") %></td>
            <tr bgcolor="#ccff99">
            <td><asp:Button CommandName="ID" Text=<%# DataBinder.Eval(Container.DataItem, "au_id") %>
                                    runat=server ID="Button2"/></td>
            <td><%# DataBinder.Eval(Container.DataItem, "au_fname") %></td>
            <td><%# DataBinder.Eval(Container.DataItem, "au_lname") %></td>
            <td><%# DataBinder.Eval(Container.DataItem, "address") %></td>


'Code Behind

Imports System.Data.SqlClient

Public Class ASPRepeater
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents Repeater1 As System.Web.UI.WebControls.Repeater

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        If Not IsPostBack Then
            Dim sqlCon As New SqlConnection("Password=test;Persist Security Info=True;User ID=sa;Initial Catalog=pubs;Data Source=(local)")

            Dim ds As New DataSet
            Dim SqlDataAdapter1 As SqlDataAdapter
            Dim sqlCommand1 As SqlCommand
            Dim strSQLQuery As String = "SELECT * FROM Authors"

            sqlCommand1 = New SqlCommand(strSQLQuery, sqlCon)
            SqlDataAdapter1 = New SqlDataAdapter(sqlCommand1)

            SqlDataAdapter1.Fill(ds, "employee_record")
            Repeater1.DataSource = ds

        End If

    End Sub

    Private Sub Repeater1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles Repeater1.ItemCommand

        If e.CommandName = "ID" Then
            Response.Write("ID selected is " & _
                CType(e.CommandSource, Button).Text())
        End If

    End Sub
End Class


Good Luck.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mitchell_Author Commented:

That does work.. now I am wondering, is there any way I could adopt that to have different text on the button? like the word "Edit" and have it check a hidden label for the value?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.