【发布时间】:2014-05-09 20:59:52
【问题描述】:
我有一个gridview,数据库中有itime_id、日期和分钟。
我想计算复选框选中的总分钟数。我正在使用 asp.net 和 mysql。在这里,当我运行这个网页时,我选择了复选框,我有一个像“NaN”这样的错误。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="hesaplama.aspx.cs" Inherits="hesaplama" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("input[type=checkbox]").change(function () {
var totalminute = 0, ctlPrice;
$('#GridView1 tr').each(function () {
if ($(this).find('input:checkbox').attr("checked")) {
ctlPrice = $(this).find('[id$= lblListPrice]');
totalminute += parseInt(ctlPrice.text().replace(/[^\d\.]/g, ''));
}
$("#<%=GridView1.ClientID %>
[id*=lblTotal]").text(totalminute.toFixed(2));
});
});});
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" ShowFooter="true" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="itime_id" HeaderText="itime_id" />
<asp:TemplateField HeaderText="date">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("date")%>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="Label2" runat="server" Text="Total"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="minute">
<ItemTemplate>
<asp:Label ID="lblListPrice" runat="server" Text='<%#Eval("minute")%>'> </asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotal" runat="server" Text=""></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
protected void Page_Load(object sender, EventArgs e)
{
MySqlConnection con = new MySqlConnection(Globals.CONNECTION_STRING);
con.Open();
string sql = "SELECT * FROM project p,issue_time t";
MySqlCommand komut = new MySqlCommand(sql, con);
MySqlDataReader okuyucu = komut.ExecuteReader();
GridView1.DataSource = okuyucu;
GridView1.DataBind();
con.Close();
con.Dispose();
}
}
【问题讨论】: