Ci sarà sicuramente un metodo più elegante, ma questo va:
ASPX
codice:
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" DataSourceID="sorgentedati">
<Columns>
<asp:BoundField DataField="quantita1" HeaderText="Q1" />
<asp:BoundField DataField="quantita2" HeaderText="Q2" />
<asp:TemplateField>
<ItemTemplate>
Tot: <asp:Label ID="lbTot" runat="server" Text="--"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Opzioni" ShowEditButton="true" />
</Columns>
</asp:GridView>
VB:
codice:
Protected Sub gv_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowIndex = CInt(Session("indiceriga")) Then
Dim tot As Label = DirectCast(e.Row.Cells(2).FindControl("lbtot"), Label)
If Not IsNothing(Session("tot")) Then
tot.Text = Session("tot")
End If
End If
End If
End Sub
Protected Sub gv_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gv.RowUpdating
Dim q1 As Integer = CInt(e.NewValues("quantita1"))
Dim q2 As Integer = CInt(e.NewValues("quantita2"))
Session("tot") = 0
Session("tot") = q1 + q2
Session("indiceriga") = e.RowIndex
End Sub