Hi, An Easy way to find Label inside Gridview through Javascript.
Label control actually renfered like Span the Html Control. you can see by Using Firebug
In GridView
<asp:TemplateField HeaderText="Employee Name" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="110px">
<ItemTemplate>
<asp:Label ID="lblDisplayEmp" runat="server" Text='<%# Eval("DisplayEmpName") %>'></asp:Label>
<asp:Label ID="hidEmpname" style="display:none;" runat="server" Text='<%# Eval("EmpName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
var grd = document.getElementById("<%= GridView1.ClientID %>");
for (i = 1; i < grd.rows.length; i++) {
var empName = grd.rows[i].cells[17].getElementsByTagName("span");
alert(empName[1].innerHTML);
}
Note : empName[1].innerHTML- it will give you first label
empName[0].innerHTML it will give you Second label
Label control actually renfered like Span the Html Control. you can see by Using Firebug
In GridView
<asp:TemplateField HeaderText="Employee Name" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="110px">
<ItemTemplate>
<asp:Label ID="lblDisplayEmp" runat="server" Text='<%# Eval("DisplayEmpName") %>'></asp:Label>
<asp:Label ID="hidEmpname" style="display:none;" runat="server" Text='<%# Eval("EmpName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
var grd = document.getElementById("<%= GridView1.ClientID %>");
for (i = 1; i < grd.rows.length; i++) {
var empName = grd.rows[i].cells[17].getElementsByTagName("span");
alert(empName[1].innerHTML);
}
Note : empName[1].innerHTML- it will give you first label
empName[0].innerHTML it will give you Second label