Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-03-2006, 06:12 AM   #1 (permalink)
rikb53
Registered User
 
Join Date: Jan 2006
Posts: 29
rikb53 is on a distinguished road
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
rikb53 is offline   Reply With Quote
Old 03-04-2006, 10:27 AM   #2 (permalink)
rdove
Masked Moderator
 
rdove's Avatar
 
Join Date: May 2002
Location: Indianapolis, IN
Posts: 260
rdove is on a distinguished road
Every time an asp.net event occurs, the Page_Load event i triggered.

Try using

If Not Page.isPostBack Then
'execute your function call
End If
__________________
~Ryan

rdove is offline   Reply With Quote
Old 03-04-2006, 02:13 PM   #3 (permalink)
rikb53
Registered User
 
Join Date: Jan 2006
Posts: 29
rikb53 is on a distinguished road
will do. yeah, i finally gave up on it and made everything table driven using temp tables. works fine, but i was hoping to do this all Using Collections in memory.
i also thought, of recycling the contents of the datatable along with the new row that's being added, but went the table-driven way before i got to that point
thanks for the help
rik
rikb53 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 07:27 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting