![](/img/trans.png)
[英]Sending data from FormView to my database using SqlDataSource
[英]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" />
<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>
谢谢!
您可以创建一些演示文稿帮助程序类,如下所示:
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.