Reputation: 1
I'm messing with this problem for about 2 days now and searched on many boards for a solution to solve the problem :(
I wrote via linq XML Attributes in my DataGrids Column named "Betrag".
Now I want to get all of those Entries and then sum them up to one number ( all entries of the column are numbers!).
I hope somebody can help me with this problem.
Best Regards, Fabian
Now some code :
data = new List<Daten>();
data = (from datensatz in doc1.Descendants("datensatz")
select new Daten
{
//datum = "27.6.2012",
datum =datensatz.Attribute("datum").Value,
//zweck = "Eröffnung",
zweck =datensatz.Attribute("zweck").Value,
//empfang = benutzer,
empfang =datensatz.Attribute("empfang").Value,
//betrag = "0€"
betrag =datensatz.Attribute("betrag").Value + "€"
}).ToList();
this.Daten.ItemsSource = data;
//THIS CODE ADDS THE ATTRIBUTES TO MY GRID
then I tried this :
kontostand += Convert.ToInt32(Daten.Columns[3].GetCellContent(1).ToString());
Upvotes: 0
Views: 420
Reputation: 6070
This :
kontostand += Convert.ToInt32(Daten.Columns[3].GetCellContent(1).ToString());
Should be like this if its an asp grid:
kontostand += Convert.ToInt32(Daten.Rows.Cells[3].innerText);
If not then you need to loop the rows.
Upvotes: 0
Reputation: 10243
Why not just do something like this...
var sum = data.Sum(item=>item.betrag);//you might have to parse as number.
you could put that value in a property on the page and then put a databinding expression wherever you want to display the value.
I think you should avoid trying to sum the values in the cells.
Also, I think you should make the betrag property an integer, if possible. You could always add the symbol by using String.Format on the code in front.
Upvotes: 1