Protected Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button5.Click
Dim dt As New DataTable
Dim dr As DataRow
Dim SelectedRow As Boolean
Dim ProductName As String
Dim Productpr As Integer
Dim Products As Integer
Dim totle As Integer
Dim toa As Integer = 0.0
'*** Column ***'
dt.Columns.Add("Name")
dt.Columns.Add("จำนวน")
dt.Columns.Add("ราคา")
dt.Columns.Add("รวม")
For Each gvr As GridViewRow In GridView1.Rows
SelectedRow = DirectCast(gvr.FindControl("Cb"), CheckBox).Checked
If SelectedRow = True Then
ProductName = DirectCast(gvr.Cells(2).Text, String)
Productpr = DirectCast(gvr.FindControl("textbox7"), TextBox).Text
Products = DirectCast(gvr.Cells(7).Text, String)
totle = Productpr * Products
toa += totle
'*** Rows ***
dr = dt.NewRow
dr("Name") = ProductName
dr("จำนวน") = Productpr
dr("ราคา") = Products
dr("รวม") = totle
dt.Rows.Add(dr)
End If
Next
dr = dt.NewRow
dr("Name") = "รวมเป็นเงิน"
dr("รวม") = toa
dt.Rows.Add(dr)
Session("SessionDt") = dt
Me.GridView2.DataSource = CType(Session("SessionDt"), DataTable)
Me.DataBind()
End Sub
If IsNothing(Session("SessionDt")) Then
dt = CType(Session("SessionDt"), DataTable)
End If
dr = dt.NewRow
dr("Name") = ProductName
dr("จำนวน") = Productpr
dr("ราคา") = Products
dr("รวม") = totle
dt.Rows.Add(dr)