0

这是我的标记

<%@ Page Title="Daily Expenses" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Daily Expenses.aspx.cs" Inherits="Daily_Expenses" %>

函数 calendar_datechange() { __doPostBack('txtCalendar', 'txtCalendar_TextChanged'); }

    function Calculate_Difference() {
        alert("Hello");
    }
</script>
<asp:ToolkitScriptManager ID="AjaxScript" runat="server"></asp:ToolkitScriptManager>
&nbsp;    &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp; 
<asp:TextBox ID="txtCalendar" runat="server" 
    ontextchanged="txtCalendar_TextChanged"></asp:TextBox>

<%--<asp:PopupControlExtender ID="txtCalendar_PopupControlExtender" runat="server" 
    DynamicServicePath="" Enabled="True" ExtenderControlID="" PopupControlID="Panel1"
    TargetControlID="txtCalendar">
</asp:PopupControlExtender>

<asp:Panel ID="Panel1" runat="server">
<h2>Hello There</h2>
</asp:Panel>--%>
<asp:CalendarExtender ID="CalendarControl"  runat="server" OnClientDateSelectionChanged="calendar_datechange" TargetControlID="txtCalendar" PopupButtonID="CalendarButton">
</asp:CalendarExtender>
<%--<ajaxToolkit:CalendarExtender ID="CalendarControl" runat="server" OnClientDateSelectionChanged="calendar_datechange" TargetControlID="txtCalendar" PopupButtonID="CalendarButton"></ajaxToolkit:CalendarExtender>--%>
<asp:Button ID="CalendarButton" runat="server" Text="Calendar" />
<br />
<br />
<br />
<asp:ListView ID="ListView1" runat="server" DataKeyNames="SNO" 
    DataSourceID="SqlDataSource1" InsertItemPosition="LastItem">
    <AlternatingItemTemplate>
        <li style="background-color: #FFF8DC;">SNO:
            <asp:Label ID="SNOLabel" runat="server" Text='<%# Eval("SNO") %>' />
            <br />
            Taxinreal:
            <asp:Label ID="TaxinrealLabel" runat="server" Text='<%# Eval("Taxinreal") %>' />
            <br />
            Taxinpercent:
            <asp:Label ID="TaxinpercentLabel" runat="server" 
                Text='<%# Eval("Taxinpercent") %>' />
            <br />
            Amount:
            <asp:Label ID="AmountLabel" runat="server" Text='<%# Eval("Amount") %>' />
            <br />
            NetAmount:
            <asp:Label ID="NetAmountLabel" runat="server" Text='<%# Eval("NetAmount") %>' />
            <br />
            DateTakenPlace:
            <asp:Label ID="DateTakenPlaceLabel" runat="server" 
                Text='<%# Eval("DateTakenPlace") %>' />
            <br />
            <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
            <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                Text="Delete" />
         <asp:Button ID="Differencebutton" runat="server"  Text="Calculate Difference" OnClientClick="Calculate_Difference" />
        </li>
    </AlternatingItemTemplate>
    <EditItemTemplate>
        <li style="background-color: #008A8C;color: #FFFFFF;">SNO:
            <asp:Label ID="SNOLabel1" runat="server" Text='<%# Eval("SNO") %>' />
            <br />
            Taxinreal:
            <asp:TextBox ID="TaxinrealTextBox" runat="server" 
                Text='<%# Bind("Taxinreal") %>' />
            <br />
            Taxinpercent:
            <asp:TextBox ID="TaxinpercentTextBox" runat="server" 
                Text='<%# Bind("Taxinpercent") %>' />
            <br />
            Amount:
            <asp:TextBox ID="AmountTextBox" runat="server" Text='<%# Bind("Amount") %>' />
            <br />
            NetAmount:
            <asp:TextBox ID="NetAmountTextBox" runat="server" 
                Text='<%# Bind("NetAmount") %>' />
            <br />
            DateTakenPlace:
            <asp:TextBox ID="DateTakenPlaceTextBox" runat="server" 
                Text='<%# Bind("DateTakenPlace") %>' />
            <br />
            <asp:Button ID="UpdateButton" runat="server" CommandName="Update" 
                Text="Update" />
            <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                Text="Cancel" />
                <asp:Button ID="Differencebutton" runat="server" CommandName="Difference" OnClientClick="Calculate_Difference" Text="Calculate Difference" />
        </li>
    </EditItemTemplate>
    <EmptyDataTemplate>
        No data was returned.
    </EmptyDataTemplate>
    <InsertItemTemplate>
        <li style="">Taxinreal:
            <asp:TextBox ID="TaxinrealTextBox" runat="server" 
                Text='<%# Bind("Taxinreal") %>' />
            <br />
            Taxinpercent:
            <asp:TextBox ID="TaxinpercentTextBox" runat="server" 
                Text='<%# Bind("Taxinpercent") %>' />
            <br />
            Amount:
            <asp:TextBox ID="AmountTextBox" runat="server" Text='<%# Bind("Amount") %>' />
            <br />
            NetAmount:
            <asp:TextBox ID="NetAmountTextBox" runat="server" 
                Text='<%# Bind("NetAmount") %>' />
            <br />
            DateTakenPlace:
            <asp:TextBox ID="DateTakenPlaceTextBox" runat="server" 
                Text='<%# Bind("DateTakenPlace") %>' />
            <br />
            <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                Text="Insert" />
            <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                Text="Clear" />
         <asp:Button ID="Differencebutton" runat="server" CommandName="Difference" OnClientClick="Calculate_Difference" Text="Calculate Difference" />
        </li>
    </InsertItemTemplate>
    <ItemSeparatorTemplate>
        <br />
    </ItemSeparatorTemplate>
    <ItemTemplate>
        <li style="background-color: #DCDCDC;color: #000000;">SNO:
            <asp:Label ID="SNOLabel" runat="server" Text='<%# Eval("SNO") %>' />
            <br />
            Taxinreal:
            <asp:Label ID="TaxinrealLabel" runat="server" Text='<%# Eval("Taxinreal") %>' />
            <br />
            Taxinpercent:
            <asp:Label ID="TaxinpercentLabel" runat="server" 
                Text='<%# Eval("Taxinpercent") %>' />
            <br />
            Amount:
            <asp:Label ID="AmountLabel" runat="server" Text='<%# Eval("Amount") %>' />
            <br />
            NetAmount:
            <asp:Label ID="NetAmountLabel" runat="server" Text='<%# Eval("NetAmount") %>' />
            <br />
            DateTakenPlace:
            <asp:Label ID="DateTakenPlaceLabel" runat="server" 
                Text='<%# Eval("DateTakenPlace") %>' />
            <br />
            <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
            <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                Text="Delete" />
          <asp:Button ID="Differencebutton" runat="server" CommandName="Difference" OnClientClick="Calculate_Difference" Text="Calculate Difference" />
        </li>
    </ItemTemplate>
    <LayoutTemplate>
        <ul ID="itemPlaceholderContainer" runat="server" 
            style="font-family: Verdana, Arial, Helvetica, sans-serif;">
            <li runat="server" id="itemPlaceholder" />
        </ul>
        <div style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
            <asp:DataPager ID="DataPager1" runat="server">
                <Fields>
                    <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                        ShowLastPageButton="True" />
                </Fields>
            </asp:DataPager>
        </div>
    </LayoutTemplate>
    <SelectedItemTemplate>
        <li style="background-color: #008A8C;font-weight: bold;color: #FFFFFF;">SNO:
            <asp:Label ID="SNOLabel" runat="server" Text='<%# Eval("SNO") %>' />
            <br />
            Taxinreal:
            <asp:Label ID="TaxinrealLabel" runat="server" Text='<%# Eval("Taxinreal") %>' />
            <br />
            Taxinpercent:
            <asp:Label ID="TaxinpercentLabel" runat="server" 
                Text='<%# Eval("Taxinpercent") %>' />
            <br />
            Amount:
            <asp:Label ID="AmountLabel" runat="server" Text='<%# Eval("Amount") %>' />
            <br />
            NetAmount:
            <asp:Label ID="NetAmountLabel" runat="server" Text='<%# Eval("NetAmount") %>' />
            <br />
            DateTakenPlace:
            <asp:Label ID="DateTakenPlaceLabel" runat="server" 
                Text='<%# Eval("DateTakenPlace") %>' />
            <br />
            <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
            <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                Text="Delete" />
          <asp:Button ID="Differencebutton" runat="server" CommandName="Difference" OnClientClick="Calculate_Difference" Text="Calculate Difference" />
        </li>
    </SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ConnString %>" 
    DeleteCommand="DELETE FROM [tblexpenses] WHERE [SNO] = @SNO" 
    InsertCommand="INSERT INTO [tblexpenses] ([Taxinreal], [Taxinpercent], [Amount], [NetAmount], [DateTakenPlace]) VALUES (@Taxinreal, @Taxinpercent, @Amount, @NetAmount, @DateTakenPlace)" 
    SelectCommand="SELECT * FROM [tblexpenses] WHERE ([DateTakenPlace] = @DateTakenPlace2)" 
    UpdateCommand="UPDATE [tblexpenses] SET [Taxinreal] = @Taxinreal, [Taxinpercent] = @Taxinpercent, [Amount] = @Amount, [NetAmount] = @NetAmount, [DateTakenPlace] = @DateTakenPlace WHERE [SNO] = @SNO">
    <DeleteParameters>
        <asp:Parameter Name="SNO" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="Taxinreal" Type="Double" />
        <asp:Parameter Name="Taxinpercent" Type="Decimal" />
        <asp:Parameter Name="Amount" Type="Double" />
        <asp:Parameter Name="NetAmount" Type="Int32"/>
        <asp:Parameter DbType="Date" Name="DateTakenPlace" />
    </InsertParameters>
    <SelectParameters>
        <asp:ControlParameter ControlID="txtCalendar" DbType="Date" 
            Name="DateTakenPlace2" PropertyName="Text" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="Taxinreal" Type="Double" />
        <asp:Parameter Name="Taxinpercent" Type="Decimal" />
        <asp:Parameter Name="Amount" Type="Double" />
        <asp:Parameter Name="NetAmount" Type="Int32" />
        <asp:Parameter DbType="Date" Name="DateTakenPlace" />
        <asp:Parameter Name="SNO" Type="Int32" />
    </UpdateParameters>
</asp:SqlDataSource>
<br />
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br />
<br />
<br />

我的数据库中有一个表tblexpense。我有名为TaxinrealTaxinpercent,* Amount * NetAmount的列。* NetAmount * 是计算列,等于* (Amount-Taxinreal-Taxinpercent) * 现在我想要的是在我的 aspx 页面运行时用户必须能够插入amount,tax,taxinpercentage和根据用户提供的值NetAmount必须在运行时计算(Netamount=Amount-Tax-Taxpercentage)并插入到数据库中。为此,我有一个差异按钮,它应该执行所需的数学运算。我遇到的问题是我正在使用列表视图。现在添加一个新按钮很简单,但是我如何在差异按钮的单击事件中执行所需的数学运算,以便当列表视图处于更新模式时,用户可以更改taxinreal ,taxinpercent的值并在运行时获得结果,结果是在数据库中更新???我急需解决方案(PS 我只需要使用 Listview)。

4

1 回答 1

0

您想使用 ListView 的 OnItemCommand。

这是一个示例。

如果要执行计算,您需要在代码后面插入/更新数据库(使用 ADO.Net、实体框架或 linq-to-sql)。

于 2013-03-25T19:45:12.723 回答