i searched a lot on NET, to get the solution, but i could not find
Can anyone tell me how to access the label and textbox values of repeater control inside using th
Wrap the repeater in a div with some id, say myDiv.
<div id="myDiv">
<!-- your repeater code -->
<asp:Repeater ID="Repeater1" runat="server"...>
<ItemTemplate>
<table>...</table>
</ItemTemplate>
</asp:Repeater>
</div>
Do a
var arrTables = document.getElementById('myDiv').getElementsByTagName('table');
Now arrTables
is just array of all table elements inside the div. Find the ordinal of the desired table: For e.g. sake I am taking first table.
var tbl = arrTables[0];
Find the corresponding td of the table element:
var td = tbl.childNodes[0].childNodes[0].childNodes[0];
The above may vary based on how your browser loads the DOM and stuff. Hence I say you debug and find out for your self.
Once you get the td reference:
var txt = td.childNodes[0];
This will give the textbox. txt.nextSibling
will give the label...and so on.
<asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "empid")%>'></asp:Label>
IDs must be unique, so you can't apply the same ID to all of the labels in your repeater. Use CSS class names instead.
<asp:Label CssClass="myLabel" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "empid")%>'></asp:Label>
Since jQuery comes with .NET you can use it instead of plain JavaScript to access these elements more easily.
var thisLabel = $('.myLabel').eq(0)
where 0 is the index of the element since there can be many.