Reputation: 111
Is there a way to get one of the values given to control by entity data source, and use it in code? For example my entity loads listview with values x, y, z and I want to get only value y for further usage in code.
What i tried to do, was get value directly from a listview item that it loads it to, but somehow it returns empty string, when on view label is loaded with data:
foreach (ListViewItem item in Auction.Items)
{
var PriceName = item.FindControl("PriceName") as Label;
string pln = PriceName.Text; //Here it returns empty string
var EurName = e.Item.FindControl("EurName") as Label;
Repositories.ICurrencyRepository repo = new Repositories.ICurrencyRepository();
decimal eur = Math.Ceiling(repo.CurrencyExchange(Convert.ToDecimal(pln), "PLN", "EUR") * 100) / 100;
EurName.Text = eur.ToString();
}
Upvotes: 0
Views: 512
Reputation: 111
If someone will have the same problem, here is the answer i came up with:
protected void Auction_ItemDataBound(object sender, ListViewItemEventArgs e)
{
ListViewDataItem dataitem = (ListViewDataItem)e.Item;
decimal pln = Convert.ToDecimal(DataBinder.Eval(e.Item.DataItem, "Price"));
Repositories.ICurrencyRepository repo = new Repositories.ICurrencyRepository();
decimal eur = Math.Ceiling(repo.CurrencyExchange(pln, "PLN", "EUR") * 100) / 100;
var EurName = e.Item.FindControl("EurName") as Label;
EurName.Text = eur.ToString();
}
The key was DataItem property, it takes values that are loaded to the listview (here value is named "Price" and is taken from entity data source connected to database table). Problem was, i didn't knew of its existence.
Upvotes: 1