Currently, I am working on a project using RadGrid in ASP.NET. In the RadGrid, I have included labels to display the status of each person. My goal is to change the background color of the label based on whether the status is "available" (green background) or "Not Available" (red background). I attempted to achieve this using JavaScript but faced difficulties accessing each record within the grid.
You can view the HTML code snippet below:
<telerik:GridTemplateColumn DataField="Editor_status" HeaderText="Editor_status" ReadOnly="true">
<ItemTemplate>
<asp:Label ID="Editor_status" runat="server" Text='<%# Eval("Editor_status") %>' BackColor="SkyBlue" Font-Size="14px" CssClass="badge badge-pill hvr-grow badge-success"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
I attempted to access the label "Editor_status" using JavaScript as shown below:
<script>
$(document).ready(function () {
var a = document.getElementById("Editor_status").innerText;
function myFunction() {
if (a == "Available") {
window.alert("Available");
} else {
window.alert("Not Available");
}
}
}</script>
Unfortunately, this approach didn't work as expected and no alert was displayed. As I am still learning JavaScript, any guidance or solutions in either VB.NET or JavaScript would be greatly appreciated. Thank you for your understanding!