Saturday, March 29, 2008

Another asp.net 2.0 lesson learned

Recently I started with .net 2.0 (I know I am about 3 years late). I sort of commited myself to following BLL and databinding practices. I favor using database triggers to create history of record changes to table data. With this method in mind I have a field in my table which records the last user who updated a record. The table trigger then grabs the updated row and records the user name who last updated that record.

Now this would appear to be simple, bind every column of a GridView to a parameter in my BLL method. At some point before the BLL update method is executed, write the bound editing GridView column, with the users name to User.Identity.Name.

I tried everything but could only come up with one way to get this to work. Now I know my code has a draw back and I welcome anyones suggestion to point me down a better path.

Protected Sub GridView1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PreRender

If GridView1.EditIndex > 0 Then
Dim mytextbox As TextBox
mytextbox = GridView1.Rows(GridView1.EditIndex).Cells(14).Controls(0)
'Set user name to current user identity
mytextbox.Text = User.Identity.Name
End If

End Sub

I know that I can take control of the update method before I send it to my BLL, where I would have to assign every BLL parameter value to a column cell... But there must be a more graceful solution.

0 comments: