I have a bulk edit asp.net grid for editing meter readings. The current meter reading is displayed in a label and the user will enter the new meter reading in a textbox on the same row. I need to be able to make sure the entered reading is not less than the current meter reading in the label. I have added CssClass names to the label and textbox and am able to get the entered value of the textbox by attaching a function to the blur event of the textbox but I can’t get the value of the label. Here is the code for the grid
<asp:GridView ID="gvSiteGeneratorReading" runat="server" DataSourceID="sdsEquipmentMeterReadings"
DataKeyNames="EquipmentMeterID" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Equipment Description">
<ItemTemplate >
<asp:Label ID="lblMeterDescription" runat="server" Text='<%# Eval("MeterDescription") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Reading" SortExpression="MeterReading">
<ItemTemplate>
<asp:Label ID="lblLastMeterReading" CssClass="LastReading" runat="server" Text='<%# Eval("LastMeterReading") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="New Reading">
<ItemTemplate>
<asp:TextBox ID="txtNewReadingValue" CssClass="NewReading" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The jQuery I have so far to alert the value of the New Reading is:
<script>
$(document).ready(function () {
$(".NewReading").blur(function () {
var enteredVal = $(this).val();
alert(enteredVal);
});
});
</script>
You can retrieve LastMeterReading column value like this