-1
我已經在ASPxGridView中加載數據,當我點擊編輯鏈接時,數據以編輯模式(PopupForm模式)顯示。 當用戶更改數量字段值時,數量字段將根據數量字段值與價格字段值的乘積進行更新。 金額將會乘以價值。之後用戶將點擊更新鏈接,數據將在數據庫中修改。ASPxGridView如何將編輯模式中的兩個字段相乘並顯示在第三個字段中
這裏是我寫
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" EnableTheming="True" KeyFieldName="transaction_id" OnRowCommand="ASPxGridView1_RowCommand" OnRowUpdated="ASPxGridView1_RowUpdated" OnRowUpdating="ASPxGridView1_RowUpdating" Theme="Metropolis">
<Columns>
<dx:GridViewCommandColumn ShowDeleteButton="True" ShowEditButton="True" VisibleIndex="0">
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="item_number" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="item_description" VisibleIndex="2">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="item_unit" VisibleIndex="3">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="item_quantity" VisibleIndex="4">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="item_price" VisibleIndex="5">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="item_amount" VisibleIndex="6">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="voucher_number" VisibleIndex="7">
</dx:GridViewDataTextColumn>
</Columns>
<SettingsBehavior ConfirmDelete="True" />
<SettingsEditing Mode="PopupEditForm">
</SettingsEditing>
<Settings ShowFilterRow="True" ShowFooter="True" />
</dx:ASPxGridView>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:item_detailConnectionString %>" DeleteCommand="DELETE FROM [tbl_item_detail_transactions] WHERE [transaction_id] = @transaction_id" InsertCommand="INSERT INTO [tbl_item_detail_transactions] ([item_number], [item_description], [item_unit], [item_quantity], [item_price], [item_amount], [voucher_number]) VALUES (@item_number, @item_description, @item_unit, @item_quantity, @item_price, @item_amount, @voucher_number)" SelectCommand="SELECT *, (item_quantity * item_price) as item_amount2 FROM [tbl_item_detail_transactions]" UpdateCommand="UPDATE [tbl_item_detail_transactions] SET [item_number] = @item_number, [item_description] = @item_description, [item_unit] = @item_unit, [item_quantity] = @item_quantity, [item_price] = @item_price, [item_amount] = @item_amount, [voucher_number] = @voucher_number WHERE [transaction_id] = @transaction_id">
<DeleteParameters>
<asp:Parameter Name="transaction_id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="item_number" Type="Int32" />
<asp:Parameter Name="item_description" Type="String" />
<asp:Parameter Name="item_unit" Type="Int32" />
<asp:Parameter Name="item_quantity" Type="Int32" />
<asp:Parameter Name="item_price" Type="Int32" />
<asp:Parameter Name="item_amount2" Type="Int32" />
<asp:Parameter Name="voucher_number" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="item_number" Type="Int32" />
<asp:Parameter Name="item_description" Type="String" />
<asp:Parameter Name="item_unit" Type="Int32" />
<asp:Parameter Name="item_quantity" Type="Int32" />
<asp:Parameter Name="item_price" Type="Int32" />
<asp:Parameter Name="item_amount" Type="Int32" />
<asp:Parameter Name="voucher_number" Type="Int32" />
<asp:Parameter Name="transaction_id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
下面是JavaScript代碼
<script src="Scripts/jquery-1.8.2.js"></script>
<script src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
$(function() {
$("#ASPxGridView1").find("input[title='item_quantity']").blur(function() {
var item_quantity = $(this).val();
var item_price = $("#ASPxGridView1").find("input[title='item_price']").val();
if (item_quantity != "" && item_price != "") {
var total = parseInt(item_price) + parseInt(item_quantity);
$("#ASPxGridView1").find("input[title='item_amount']").val(total);
} else {
$("#ASPxGridView1").find("input[title='item_amount']").val("");
}
})
})
</script>
你的問題是什麼?我所看到的只是一組用戶應該做的事情的陳述,而不是你在做代碼時遇到的麻煩。 – freefaller 2015-03-03 11:15:25