Hello
i'm trying to get the sum of column [Exit Units] in a repeater
with dataTable as datasource, i used to do like that in Page_Load:
- if (!IsPostBack)
- {
- DataTable dt = (DataTable)Session["CheckedRows"];
- Repeater1.DataSource = dt;
- Repeater1.DataBind();
- foreach (RepeaterItem item in Repeater1.Items)
- {
- if (item.ItemType == ListItemType.Item ||item.ItemType == ListItemType.Footer)
- {
- Label lblExitSum = (Label)item.FindControl("lblExitCount");
- string sum = dt.Compute("sum(ExitUni)", string.Empty).ToString();
- lblExitSum.Text = sum;
- }
- }
- }
but the output is strange and doesn't appeare in the footer after the last row like this:
| Item No | Goods Description | UOM | Exit Units | Units New Balance | WT Balance | Exit WT | Exit Amount(LC) |
|---|---|---|---|---|---|---|---|
| S440862340A | C RAMP AW165 PAINT-S440862340A | ???? | 1 | 1.000000 | 0.365000 | 0.182500 | 146.797040 |
| 2 | |||||||
| F1SEMIAUTO0441 | C.TO F1-L-16-M 220/240 50HZ MF C.CONT-F1SEMIAUTO0441 | ???? | 1 | 1.000000 | 1.160000 | 0.580000 | 1772.856560 |
the total of the column is 2 but it appears after the first row
Dilip GuptaPosted Dec 12, 2016, 12:09 AM
DataTable dt =newDataTable();dt.Columns.AddRange(newDataColumn[2] {newDataColumn("SubjectName",typeof(string)),newDataColumn("Marks",typeof(int)) });dt.Rows.Add("English", 56);dt.Rows.Add("Hindi", 75);dt.Rows.Add("Maths", 61);dt.Rows.Add("Science", 79);Repeater1.DataSource = dt;Repeater1.DataBind();inttotalMarks = dt.Select().Sum(p => Convert.ToInt32(p["Marks"]));(Repeater1.Controls[Repeater1.Controls.Count - 1].Controls[0].FindControl("lblTotal")asLabel).Text = totalMarks.ToString();}}Midhun TpPosted Dec 14, 2016, 4:40 AM