[英]how to retrieve data from my database (formview) and multiply it, visual studio
I am using Visual Studio 2010, and I created a site (.aspx). 我正在使用Visual Studio 2010,并且创建了一个网站(.aspx)。
I have an sql database (.mdf file) and I want to retrieve ONLY one value of the table and multiply it with a specific number. 我有一个sql数据库(.mdf文件),我只想检索表的一个值并将其乘以一个特定的数字。 I have used SqlDataSource and formview for this, and everything is ok, I have my number at the formview but how do I multiply this number with a variable??
我已经为此使用SqlDataSource和formview,一切都很好,我在formview上有我的数字,但是如何将这个数字与变量相乘呢?
my code is: 我的代码是:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="apodeiksi.aspx.cs" Inherits="apodeiksi" %> <%@页面语言=“ C#” AutoEventWireup =“ true” CodeFile =“ apodeiksi.aspx.cs” Inherits =“ apodeiksi”%>
<%@ Register assembly="System.Web.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" namespace="System.Web.UI.WebControls" tagprefix="asp" %> <%@注册程序集=“ 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" />
<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" />
<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>
Thank you! 谢谢!
You can create some presentation helper class like this: 您可以创建一些演示文稿帮助程序类,如下所示:
public static class UiHelper
{
public static string MultiplyValue(object value, int multiplier)
{
return (((int)value)*multiplier).ToString();
}
}
And than in your aspx instead of 而且比你的aspx而不是
<%# Eval("PRICE") %>
use 采用
<%# UiHelper.MultiplyValue(Eval("PRICE"), 5) %>
Also you can create any methods and format any value from database as you want. 您还可以根据需要从数据库中创建任何方法并格式化任何值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.