2

I have a repeater and a lable inside the repeater, that is binded with a table having 5 row each row has username that is binded to lable control.

<asp:Repeater ID="PostsRepeater" runat="server">
            <ItemTemplate>
                <asp:Label ID="lblUserName" runat="server" Text="<%#Eval("username") %>"></asp:Label>
                <asp:TextBox ID="txtUser" runat="server"></asp:TextBox>
            <input id="btnGetUser" type="button" value="Get" />
            </ItemTemplate>
        </asp:Repeater>

i want to get the name of user that has some values in the textbox on button click using javascript

Usf Noor
  • 217
  • 1
  • 4
  • 16
  • foreach (Repeater objRepe in Repeater1.Items) { Label Name= (Label)item.FindControl("Name"); if(Name!=null) { //Your Code } Image img= (Image)objRepe.FindControl("Img"); if(img!=null) { //your code } } – NishantMittal Apr 04 '16 at 07:07
  • can u please give me javascript code on button click?? – Usf Noor Apr 04 '16 at 07:09
  • try this.. http://stackoverflow.com/questions/8342583/access-repeater-values-using-javascript – NishantMittal Apr 04 '16 at 07:13

1 Answers1

0

The <asp:Label..> ware rendered as html span tags. Since the labels are inside the <asp:Repeater..> they will named in the following manner:

Span id will be dynamically generated as "repeater_id" + "_" + "ctl00" + "_" + label_id So in your case the id for label in the first row will be: "PostsRepeater_ctl00_lblUserName" You can simply inspect the element and check for the id. you can write events based on this id inside script or can iterate through all labels by following code: subject to the condition that you need to specify cssClass for labels as rptLabels

var elemArray = document.getElementsByClassName('rptLabels');
for(var i = 0; i < elemArray.length; i++){
    var elem = elemArray[i]; // this will be your label
   alert(elem.innerText); 
}

example

sujith karivelil
  • 28,671
  • 6
  • 55
  • 88