List Info

Thread: Array




Array
user name
2006-03-14 02:06:24
Hey All,

I have an app that shows users query results in a datagrid
bound to a dataset. The users indicate which rows they want
to see further details on by checking (or not) a checkbox on
each row. I save their choices to a db table when they click
a 'save' link, w/the below code. This works fine for
adding newly checked codes to the user's session, but now I
need the app to also *remove* codes that the user un-checks,
which that code doesn't do.

Now I could just blindly send a DELETE operation to the db
for every row that *isn't* checked, but I'd like to avoid
that traffic if it's possible. So as I loop through my
rows, when I find a row whose checkbox isn't checked, I
want to know whether it used to be checked--whether was
checked when I originally sent it down to the client. I've
got viewstate enabled on the grid, so I'm thinking it
should be possible, I just don't know how.

My naïve hope was that each DataGridItem would have
something in its .DataItem property that I could cast to a
DataRow, and get at the previous value that way. But no
dice--.DataItem is Nothing in every case.

(In case it matters, the checkbox column is an
<asp:TemplateColumn> that contains an
<asp:CheckBox> whose checked property is bound to the
appropriate datacolumn. All my other columns are
<asp:BoundColumns>.)

Can anybody throw me a clue on this?

Thanks!

-Roy

Private Sub SaveCodes(ByVal dg As DataGrid _
                     , ByVal chkname As String _
                     , ByVal lbl As Label _
                     , ByVal CodeType As CodeTypes)
   Dim chk As CheckBox
   Dim codes As New ArrayList
   For Each i As DataGridItem In dg.Items
      chk = CType(i.FindControl(chkname), CheckBox)
      If chk.Checked Then
         codes.Add(Integer.Parse(CType(i.Controls(1),
TableCell).Text))
      Else
         ' How do I find out the previous value of
'selected'? so I can process de-selections?
         ' i.DataItem is Nothing!
      End If
   Next
   If codes.Count > 0 Then
      Try
         If Globals.scnn.State <> ConnectionState.Open
Then Globals.scnn.Open()
         For Each code As Integer In codes
            InsertCode(code, CodeType,
Me.User.Identity.Name, Session.SessionID)
         Next
      Finally
         If Globals.scnn.State = ConnectionState.Open Then
Globals.scnn.Close()
      End Try
      Me.lbReviewCodes.Enabled = True
   End If
   With lbl
      .Text = "Saved " &
codes.Count.ToString & " codes."
      .Visible = True
   End With
End Sub

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Instance efficiency (sp?)
user name
2006-06-21 22:27:37
I have an app that on a page might create an instance of a
data access
layer using it in several places, for populating controls,
updating
tables, etc.  At some point in the page I might create a
business object
that consists of an ArrayList of objects populated from the
database.
Is it more efficient to pass the business object an instance
of the data
access layer, or pass it a connection string and let it
instantiate it?
Thanks, Mark

--
====================
Mark Aurit
MarkAuritgmail.com

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Instance efficiency (sp?)
user name
2006-06-21 22:52:10
For me, my business objects get instantiated by an
ID or by a data object.  Also I use public static methods
that return the object type.  That way I can return
"null"
if the id or dataobject is invalid or the user does not
have access to it.

Also, I create business object collection objects instead
of using ArrayList.  That way I can write other methods on
the collection to do things to all of the objects, even load
the collection list.

So to get back to your question, it should be efficient so
you don't have to make another database call from the
business object.  Especially if you are making a call per
business object load.  You should be able to loop through
the dataset returned and create business objects from it.

Hope this Helps...
_____________________________
Robert L. Taylor
Senior Web/Systems Developer
Engage/G2 Program Manager
DataStarUSA, Inc.
rtaylordatastarusa.com
http://www.datastarusa.com


DataStarUSA is your leading Nationwide Technology Deployment
and
Maintenance Resource.  Our differentiators include
Geographic Reach,
Experience, Speed, and Consistency.  We deliver results at
the lowest total
cost.  To find out more visit our website.



                                                            
          
             Mark Aurit                                     
          
             <markauritGMAIL.                     
                   
             COM>                                        
              To
             Sent by:                  DOTNET-WEBDISCUSS.DEVELOP.COM  
             "Discussion of                           
                 cc
             building .NET                                  
          
             applications                                   
      Subject
             targeted for the          [DOTNET-WEB] Instance
efficiency
             Web"                      (sp?)          
                
             <DOTNET-WEBDISCU                      
                  
             SS.DEVELOP.COM>                             
             
                                                            
          
                                                            
          
             06/21/2006 05:27                               
          
             PM                                             
          
                                                            
          
                                                            
          
             Please respond to                              
          
              "Discussion of                          
                
               building .NET                                
          
               applications                                 
          
             targeted for the                               
          
                   Web"                               
                
             <DOTNET-WEBDISCU                      
                  
              SS.DEVELOP.COM>                            
             
                                                            
          
                                                            
          




I have an app that on a page might create an instance of a
data access
layer using it in several places, for populating controls,
updating
tables, etc.  At some point in the page I might create a
business object
that consists of an ArrayList of objects populated from the
database.
Is it more efficient to pass the business object an instance
of the data
access layer, or pass it a connection string and let it
instantiate it?
Thanks, Mark

--

====================
Mark Aurit
MarkAuritgmail.com

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com


===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )