FormView, Eval, and formula

L

Larry Bud

Is this possible:

I have a drop down with a variety of exchange rates (1, .85, .094783,
etc)

I have a formview which retrieves a row of data with dollar figures.
Can I change the databinding to multiply the value (using EVAL) with
the exchange rate?

On the page load, I'm settings a public variable of type double to the
value of the drop down. This works.

But the

Eval("fzn_matl") * exchange_rate

while it doesn't throw an error, it just seems like it's ignoring the
*exchange_rate portion
 
G

Guest

Howdy,

It should work, example:

-- begin code --

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="ExchangeRate.aspx.cs" Inherits="ExchangeRate" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>

<script runat="server">

internal class BusinessObject
{
public BusinessObject(int fzn_matl)
{
// fzn_matl whateever it is :)
_fzn_matl = fzn_matl;
}

private int _fzn_matl;
/// <summary>
///
/// </summary>
public int fzn_matl
{
get
{
return this._fzn_matl;
}
set
{
this._fzn_matl = value;
}
}
}

protected void Page_Load(object source, EventArgs e)
{
if (!IsPostBack)
{
calculator.DataSource = new BusinessObject[] { new BusinessObject(200) };
calculator.DataBind();
}
}

protected void exchangeRates_SelectedIndexChanged(object sender, EventArgs
e)
{
calculator.DataSource = new BusinessObject[] { new BusinessObject(200) };
calculator.DataBind();
}

protected double CurrentExchangeRate
{
get
{
double rate;
return double.TryParse(exchangeRates.SelectedValue, out rate) ? rate :
1.0d;
}
}

</script>

<form id="form1" runat="server">
<div>
<asp:DropDownList runat="server" ID="exchangeRates" AutoPostBack="true"
OnSelectedIndexChanged="exchangeRates_SelectedIndexChanged">
<asp:ListItem Text="1" Value="1"/>
<asp:ListItem Text="0.5" Value="0.5"/>
<asp:ListItem Text="0.4" Value="0.4"/>
<asp:ListItem Text="0.3" Value="0.3"/>
</asp:DropDownList>

<asp:FormView runat="server" ID="calculator">
<ItemTemplate>
<asp:Literal runat="server" ID="result" Text='<%# CurrentExchangeRate *
Convert.ToDouble(Eval("fzn_matl")) %>'/>
</ItemTemplate>
</asp:FormView>

</div>
</form>
</body>
</html>



-- end code --
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top