[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Getting the clicked Row value of a nested repeater

Posted on 2004-11-30
4
Medium Priority
?
414 Views
Last Modified: 2012-06-21
Hi All:

Here's my repeater:

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

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.

Thanks,
Mitch
0
Comment
Question by:Mitchell_
  • 2
4 Comments
 
LVL 5

Expert Comment

by:dba_netanya
ID: 12708572
in rptDivision:]
OnItemDataBound="Item_Created"


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

Author Comment

by:Mitchell_
ID: 12708832
Hi;

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

Thanks
0
 
LVL 8

Accepted Solution

by:
mani_sai earned 2000 total points
ID: 12709107
Sample Working Code :

-------------------------------------------------------------------------------------
'HTML Page Code:

<HTML>
<HEAD>
<title>ASPRepeater</title>
<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="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
      <asp:Repeater id="Repeater1" runat="server">
            <HeaderTemplate>
            <table border="1">
            <tr bgcolor="#ffcc99">
            <th>ID</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Address</th>
            </tr>
                                  </HeaderTemplate>
            <ItemTemplate>
            <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>
            </ItemTemplate>
            <AlternatingItemTemplate>
            <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>
            </tr>
            </AlternatingItemTemplate>
            <FooterTemplate>
            </table>
            </FooterTemplate>
                      </asp:Repeater>
            </form>
      </body>
</HTML>


-------------------------------------------------------------------------

'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.
        InitializeComponent()
    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
            Repeater1.DataBind()

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

Author Comment

by:Mitchell_
ID: 12709183
mani_sai:

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Screencast - Getting to Know the Pipeline
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question