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 the javascript ?
This is my code
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<table id="t1" width="200px:" style="background-color: skyblue" runat="server">
<tr>
<td>
<asp:TextBox ID="TextBox3" Text='<%#DataBinder.Eval(Container.DataItem, "empid")%>'
runat="server" />
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "empid")%>'></asp:Label>
<asp:Label ID="lblname" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "ename")%>'></asp:Label>
<br />
<br />
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
Now i want to access the label, textbox of repeater using javascript
@Diodeus
I tried your code
function submitAll() {
var thisLabel = $('.myLabel').eq(0);
alert(thisLabel);
}
But i got the result in alert as
[object Object]
and @deostroll
I tried your code this way
But not getting anything
function GetData() {
var arrTables = document.getElementById('myDiv').getElementsByTagName('table');
var tbl = arrTables[0];
var td = tbl.childNodes[0].childNodes[0].childNodes[0];
var txt = td.childNodes[0];
alert(txt.value);
}
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.
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.