我正在使用Jquery设置GridView内部的HiddenField的值。
$(this).siblings('input[type="hidden"]').val(roundedvalue);
但我无法使用
访问相同内容HiddenField hidn= (HiddenField)gvdtaxes.Rows[2].FindControl("hidnin");
hidn.Value
始终为空""
,但在我使用Chrome中的inspect元素检查时它有一个值。
标记
<asp:GridView ID="gvdtaxes" runat="server" AutoGenerateColumns="False"
CssClass="tabledata">
<Columns>
<asp:TemplateField HeaderText="SrNo">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tax Type">
<ItemTemplate>
<asp:Label ID="lbltaxtype" runat="server" Text='<%# Eval("TaxCode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tax Description">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tax Value">
<FooterTemplate>
<asp:TextBox ID="txtftrtaxvalue" runat="server" class="totaltaxvalue"></asp:TextBox>
<br />
<asp:TextBox ID="txtftrfinalamount" runat="server" class="finalamount"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:TextBox ID="txttaxvalue" runat="server" class="taxvalue"></asp:TextBox>
<asp:FilteredTextBoxExtender ID="Filteredtaxvalue" runat="server"
FilterType="Numbers, Custom" TargetControlID="txttaxvalue" ValidChars="." />
<asp:HiddenField ID="hidnin" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
的Javascript
function CalculateTaxes() {
var taxvaluesum = 0;
$(".taxvalue").each(function () {
//add only if the value is number
if (!isNaN(this.value) && this.value.length != 0) {
taxvaluesum += parseFloat(this.value);
}
else {
$(this).val('0')
}
});
//$('.totaltaxvalue').val(taxvaluesum.toFixed(2));
$('.totaltaxvalue').attr("value", taxvaluesum.toFixed(2));
var finalamt = parseFloat($('.totaltaxvalue').val()) + parseFloat($('#ContentPlaceHolder1_Gridview1_txtftrvalue').val());
$('.finalamount').attr("value", finalamt.toFixed(2));
//$('.finalamount').val(finalamt.toFixed(2));
}
$(document).on('blur', ".taxvalue", function (e) {
CalculateTaxes();
var roundedvalue = parseFloat($(this).val()).toFixed(2);
$(this).val(roundedvalue);
$(this).siblings('input[type="hidden"]').val(roundedvalue);
$('#<%=hidnout.ClientID %>').val(roundedvalue);
alert($('#<%=hidnout.ClientID %>').val());
//document.getElementById().value = roundedvalue;
//alert($(this).siblings('input[type="hidden"]').val());
});
代码背后
protected void btnUpload_Click(object sender, EventArgs e)
{
try
{
HiddenField hidnin = new HiddenField();
hidnin = (HiddenField)gvdtaxes.Rows[2].FindControl("hidnin");
txtapprovedby.Text = hidnin.Value;//always blank
//some code...