私の
OnClientClick
データグリッド内のボタンをクリックしてもイベントは何もしません。このコードで何が間違っているのかを理解してください
ここに私のaspxがあります
<asp:DataGrid ID="grid3" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" Width="100%" OnItemCommand="dtgItemCommand"
OnPageIndexChanged="grid1_PageIndexChanging" EnableViewState="true" ShowFooter="true"
OnRowDataBound="GridView_RowDataBound">
<AlternatingItemStyle CssClass="tdgenap" />
<ItemStyle CssClass="tdganjil" HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" Height="30px" CssClass="tdjudul"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<HeaderStyle Font-Underline="false" Height="15px" Width="5%" HorizontalAlign="Center" BackColor="#ccffcc"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="cbTest" runat="server" Enabled="true" AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Row" >
<HeaderStyle Font-Underline="false" Height="15px" Width="5%" HorizontalAlign="Center" BackColor="#ccffcc"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:Literal ID="litID" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Row_")%>'></asp:Literal>
<%--<asp:Label id="lblID" runat="server" text='<%#DataBinder.Eval(Container.DataItem, "ID_")%>'></asp:Label>--%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Price">
<HeaderStyle Font-Underline="false" Height="30px" HorizontalAlign="Center" BackColor="#ccffcc"></HeaderStyle>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtPrice" BorderWidth="0" onkeypress="CheckNumeric(event);" onkeyup="FormatCurrency(this);" runat="server" Width="95%" Text='<%#DataBinder.Eval(Container.DataItem, "Price_", "{0:N2}")%>'> </asp:TextBox>
<%--<asp:Label id="lblName" runat="server" text='<%#DataBinder.Eval(Container.DataItem,"Name_")%>'></asp:Label> --%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Quantity">
<HeaderStyle Font-Underline="false" Height="30px" HorizontalAlign="Center" BackColor="#ccffcc"></HeaderStyle>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtQty" BorderWidth="0" onkeypress="CheckNumeric(event);" onkeyup="FormatCurrency(this);" runat="server" Width="95%" Text='<%#DataBinder.Eval(Container.DataItem, "Qty_", "{0:N2}")%>'> </asp:TextBox>
<%--<asp:Label id="lblPhone" runat="server" text='<%#DataBinder.Eval(Container.DataItem,"Phone_")%>'></asp:Label>--%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderStyle Font-Underline="false" Height="30px" HorizontalAlign="Center" BackColor="#ccffcc"></HeaderStyle>
<ItemStyle HorizontalAlign="Left" Width="30px"></ItemStyle>
<ItemTemplate>
<%--<asp:LinkButton ID="lnkCheck" runat="server" Text="Check Total" CommandName="Check"></asp:LinkButton>--%>
<asp:ImageButton ID="btnCheck" runat="server" OnClientClick="javascript: return calculate();" ImageUrl="~/images/ButtonCheck.gif"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Total">
<HeaderStyle Font-Underline="false" Height="30px" HorizontalAlign="Center" BackColor="#ccffcc"></HeaderStyle>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblTotal" BorderWidth="0" runat="server" Width="95%" Text='<%#DataBinder.Eval(Container.DataItem, "Total_")%>'> </asp:Label>
<%--<asp:Label id="lblPhone" runat="server" text='<%#DataBinder.Eval(Container.DataItem,"Phone_")%>'></asp:Label>--%>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
ここに私のjavascriptがあります
function calculate() {
var qty = parseFloat(document.getElementById("txtQty").value);
var price = parseFloat(document.getElementById("txtPrice").value);
alert("qty + price " +qty+" "+price);
if (isNaN(qty) || isNaN(price)) {
alert("Not a number");
} else {
var values = ggt(qty, price);
console.log(values);
if (values.valid) {
alert(values.multiply);
document.getElementById("txtTotal").innerHTML = values.multiply;
}
}
return false;
}
function ggt(x, y) {
var res = {};
if (y == 0) {
res.valid = false;
} else {
res.valid = true;
res.number = x;
res.multiply = x * y;
}
return res
}
回答 1 件
書いてくれますか。
また、ASP.NetはDataGrid内のコントロールのIDを変更します。したがって、document.getElementbyId行で何も取得しません。
これらの行は何も返しません。