簡體   English   中英

如何從數據庫(formview)中檢索數據並將其相乘,Visual Studio

[英]how to retrieve data from my database (formview) and multiply it, visual studio

我正在使用Visual Studio 2010,並且創建了一個網站(.aspx)。

我有一個sql數據庫(.mdf文件),我只想檢索表的一個值並將其乘以一個特定的數字。 我已經為此使用SqlDataSource和formview,一切都很好,我在formview上有我的數字,但是如何將這個數字與變量相乘呢?

我的代碼是:

<%@頁面語言=“ C#” AutoEventWireup =“ true” CodeFile =“ apodeiksi.aspx.cs” Inherits =“ apodeiksi”%>

<%@注冊程序集=“ System.Web.Entity,版本= 3.5.0.0,文化=中性,PublicKeyToken = b77a5c561934e089” namespace =“ System.Web.UI.WebControls” tagprefix =“ asp”%>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Αποδειξη </title>
     <link href="style.css" rel="stylesheet" type="text/css"/>
</head>
<body>

    <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" 
        EnableModelValidation="True" Height="23px" Width="70px" 
                    onpageindexchanging="FormView1_PageIndexChanging">
        <EditItemTemplate>
            PRICE:
            <asp:TextBox ID="PRICETextBox" runat="server" 
                Text='<%# Bind("PRICE", "{0}") %>' TextMode='<%# Eval("PRICE") %>' />
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                CommandName="Update" Text="Update" />
            &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </EditItemTemplate>
        <InsertItemTemplate>
            PRICE:
            <asp:TextBox ID="PRICETextBox" runat="server" Text='<%# Bind("PRICE") %>' />
            <br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                CommandName="Insert" Text="Insert" />
            &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </InsertItemTemplate>
        <ItemTemplate>
            PRICE:
            <asp:Label ID="PRICELabel" runat="server" Text='<%# Bind("PRICE") %>' />
            <br />

        </ItemTemplate>
    </asp:FormView>
                </td><br /></td></tr>
    <asp:Label ID="Label6" runat="server" Text='<%# Bind("PRICE") %>'></asp:Label>
    </table>
<p>
    <br />
    <br />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        SelectCommand="SELECT [PRICE] FROM [Flight] WHERE ([ID] = @ID)">
        <SelectParameters>
            <asp:SessionParameter Name="ID" SessionField="kratisi" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" />

    </p>




</body>

謝謝!

您可以創建一些演示文稿幫助程序類,如下所示:

public static class UiHelper
{
    public static string MultiplyValue(object value, int multiplier)
    {
        return (((int)value)*multiplier).ToString();
    }
}

而且比你的aspx而不是

<%# Eval("PRICE") %>

采用

 <%# UiHelper.MultiplyValue(Eval("PRICE"), 5) %>

您還可以根據需要從數據庫中創建任何方法並格式化任何值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM