|
OverWriting dataTable Obj on each Rows.Add
somehow im not managing whats being added to the data table and its overwriting each time i add some thing. if the DataTable is created at runtime, each postback shouldn't destroy it or so i thought.
this works great - its just overwriting each click of the first grid. i left that code out of here. im adding values to the datacolumns, then to the datarow and then add the datarow to the dataTable. but, ill be darned if it's not overwriting it. i'm missing something simple here i know.
any help is appreciated
Public Vars::
Public dt2 As New DataTable
Public aRow As DataRow
Public dcCol1 As New DataColumn("Name", GetType(String))
Public dcCol2 As New DataColumn("Dept", GetType(String))
Public dcCol3 As New DataColumn("Email", GetType(String))
i pass e.item.cells(0).text to the sub below based on what's clicked in the first datagrid::::
Private Sub addToGrid(ByVal myName As String, ByVal myemail As String, ByVal myDept As String)
Try
aRow = dt2.NewRow
dt2.Columns.Add(dcCol1)
dt2.Columns.Add(dcCol2)
dt2.Columns.Add(dcCol3)
aRow(dcCol1) = myName
aRow(dcCol2) = myDept
aRow(dcCol3) = myemail
dt2.Rows.Add(aRow)
For Each aRow In dt2.Rows
DG2.DataSource = dt2.DefaultView
DG2.DataBind()
Next
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
|