So that I could store it in viewstate, I ended up going with a datatable. Then I can easily add rows to it and then after the user saves, I can send all the emails at once. This works pretty well. Here is the partial code where I was stumbling.
Thank you Dino !
Imports System.Data.SqlClient
Imports System.Data
Partial Class test
Inherits System.Web.UI.Page
Dim dtEmailStore As DataTable
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If ViewState("_dtEmailStore") IsNot Nothing Then
dtEmailStore = CType(ViewState("_dtEmailStore"), DataTable)
Else
Dim colRowNum As DataColumn = New DataColumn("colRowNum", System.Type.GetType("System.Int32"))
colRowNum.AutoIncrement = True
colRowNum.Unique = True
dtEmailStore = New DataTable
Dim colTo As DataColumn = New DataColumn("colTo", Type.GetType("System.String"))
Dim colCC As DataColumn = New DataColumn("colCC", Type.GetType("System.String"))
Dim colBody As DataColumn = New DataColumn("colBody", Type.GetType("System.String"))
dtEmailStore.Columns.Add(colRowNum)
dtEmailStore.Columns.Add(colTo)
dtEmailStore.Columns.Add(colCC)
dtEmailStore.Columns.Add(colBody)
End If
End Sub
Protected Sub btnInsert_Click(sender As Object, e As System.EventArgs)
Dim dr As DataRow
dr = dtEmailStore.NewRow()
dr("colTo") = "PersonTo@Rubble.com"
dr("colCC") = "PersonCC@Rubble.com"
dr("colBody") = "Testing body"
dtEmailStore.Rows.Add(dr)
dr = dtEmailStore.NewRow()
dr("colTo") = "ttttt@Rubble.com"
dr("colCC") = "ccccccc@Rubble.com"
dr("colBody") = "Testing again body"
dtEmailStore.Rows.Add(dr)
ViewState("_dtEmailStore") = dtEmailStore
Call Read()
End Sub
Protected Sub btnRead_Click(sender As Object, e As System.EventArgs)
Call Read()
End Sub
Sub Read()
Response.Write(System.DateTime.Now & "<br />")
For Each dr As DataRow In dtEmailStore.Rows
Response.Write(dr.Item("colRowNum") & " " & dr.Item("colTo") & " " & dr.Item("colCC") & " " & dr.Item("colBody") & "<br>")
Next
End Sub
End Class
</br>