I am using Visual Studio 2010, and I created a site (.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. 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??
my code is:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="apodeiksi开发者_JS百科.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" %>
<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
<%# Eval("PRICE") %>
use
<%# UiHelper.MultiplyValue(Eval("PRICE"), 5) %>
Also you can create any methods and format any value from database as you want.
精彩评论