Visual C++ .NET - sumar columna del gridview

 
Vista:
sin imagen de perfil
Val: 13
Ha mantenido su posición en Visual C++ .NET (en relación al último mes)
Gráfica de Visual C++ .NET

sumar columna del gridview

Publicado por Daniela (6 intervenciones) el 19/10/2018 19:58:44
quiero saber como puedo sumar los datos de mi gridview, dichos datos son ingresados por textbox y pasa al grid view por el boton de agregar

nota: el total lo quiero mostar en el label

gracias


Captura
y este es mi codigo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Web.UI.WebControls;
using System.Data;
 
namespace Plataforma_de_Novedades
{
    public partial class Formulario_de_transporte : System.Web.UI.Page
    {
        private static System.Data.DataSet dataset = new DataSet();
        private static System.Data.DataTable table = new DataTable("ParentTable");
        private static DataColumn column;
        private static DataRow row;
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                column = new DataColumn();
                column.DataType = System.Type.GetType("System.DateTime");
                column.ColumnName = "Fecha";
                column.AutoIncrement = false;
                column.ReadOnly = false;
                column.Unique = false;
 
                table.Columns.Add(column);
 
                column = new DataColumn();
                column.DataType = System.Type.GetType("System.String");
                column.ColumnName = "Concepto";
                column.AutoIncrement = false;
                column.ReadOnly = false;
                column.Unique = false;
 
                table.Columns.Add(column);
 
                column = new DataColumn();
                column.DataType = System.Type.GetType("System.Int32");
                column.ColumnName = "Valor";
                column.AutoIncrement = false;
                column.ReadOnly = false;
                column.Unique = false;
 
                table.Columns.Add(column);
 
                dataset.Tables.Add(table);
            }
            this.LoadData();
        }
 
        private void LoadData()
        {
            DataTable dt = new DataTable();
 
            dt.Columns.Add("Fecha");
            dt.Columns.Add("Concepto");
            dt.Columns.Add("Valor");
 
            DataRow dr = dt.NewRow();
 
            dr["Fecha"] = String.Empty;
            dr["Concepto"] = String.Empty;
            dr["Valor"] = String.Empty;
 
            dt.Rows.Add(dr);
 
            grvformatodetransporte.DataSource = dt;
           this.grvformatodetransporte.DataBind();
        }
 
        protected void grvformatodetransporte_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            GridViewRow row = e.Row;
            if (row.RowIndex > -1)
                for (int i = 0; i < row.Cells.Count; i += 1)
                    row.Cells[i].Visible = false;
        }
 
        protected void btnagregar_Click1(object sender, EventArgs e)
        {
            try
            {
                DateTime hoy = DateTime.Today;
 
                string fecha_actual = hoy.ToShortDateString();
                lblfecha.Text = fecha_actual;
            }
            catch (Exception ex)
            {
 
            }
 
            row = table.NewRow();
            row["Fecha"] = Convert.ToString(lblfecha.Text);
            row["Concepto"] = txtconcepto.Text;
            row["Valor"] = Convert.ToInt32(txtvalor.Text);
 
            table.Rows.Add(row);
            grvformatodetransporte.DataSource = dataset.Tables[0];
            grvformatodetransporte.DataBind();
        }
    }
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 13
Ha mantenido su posición en Visual C++ .NET (en relación al último mes)
Gráfica de Visual C++ .NET

sumar columna del gridview

Publicado por Daniela (6 intervenciones) el 29/01/2019 21:36:33
solución

1
2
3
4
5
6
7
8
9
10
11
12
//Suma de valor ingresado
 
//acomuladores
Int32 acom = 0;
foreach (GridViewRow row in grvformatodetransporte.Rows)
{
    Int32 total = Convert.ToInt32(((System.Web.UI.WebControls.Label)row.FindControl("lbvalor")).Text);
 
    acom = acom + total;
}
lbltotal.Visible = true;
lbltotal.Text = Convert.ToString(acom);
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
2
Comentar