?
Solved

How do I get the value of a label on a repeater?

Posted on 2015-02-09
2
Medium Priority
?
86 Views
Last Modified: 2015-02-09
I have a repeater with a label and a button (with OnClick="SaveCN")
In the saveCN function, how do I get the value of what is in the label?
0
Comment
Question by:Mike Miller
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 40599913
In your button click function use this code:
Dim lbl As Label = sender.Parent.FindControl("Label1")

Open in new window


Here's an example page:
<%@ Page Language="vb" AutoEventWireup="false" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title> EE Q_28613082 </title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        clicked: <asp:Label ID="LabelClicked" runat="server" Text="-"></asp:Label>
        <br />
        <br />
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# eval("name") %>'></asp:Label>
                <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# eval("id") %>' />
                <asp:Button ID="Button1" runat="server" Text="Button" OnClick="SaveCN" UseSubmitBehavior="false" />
                <br />
                <br />
            </ItemTemplate>
        </asp:Repeater>
    </div>
    </form>
</body>
</html>
<script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim dt As New DataTable
            dt.Columns.AddRange({New DataColumn("id", GetType(Integer)), New DataColumn("name", GetType(String))})
            For i As Integer = 1 To 10
                dt.Rows.Add({i, "Name " & i})
            Next
            Repeater1.DataSource = dt
            Repeater1.DataBind()
        End If
    End Sub

    Protected Sub SaveCN(sender As Object, e As EventArgs)
        Dim lbl As Label = sender.Parent.FindControl("Label1")
        LabelClicked.Text = lbl.Text
    End Sub

</script>

Open in new window

0
 

Author Closing Comment

by:Mike Miller
ID: 40600015
Thanks!
0

Featured Post

Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

762 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