gridview update programatically

G

Guest

I am using Visual Web Developer (vb.net) and have a gridview in a form. I can
update records using standard EDIT/UPDATE buttons. However, there are two
fields in every record (called ModifiedBy and ModifiedDate) that I use to
track who last changed data in a row and when. How do I programatically
(vb.net) enter this information in the two fields. Right now they are
template fields (EditItemTemplate) and I am using textboxes (TextBox1 and
TextBox2) for each. This is what I have tried:

Just before row update (hence row_updating event) code values of current
user and time in the two fields.

PROBLEM: data is not being saved for the two fields even though every other
edit saves fine.

Here is the code:
****************************************
Protected Sub GridView2_RowUpdating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
GridView2.RowUpdating

Dim row As GridViewRow = GridView2.Rows(e.RowIndex)
' Use the current row (which is to be updated)
If row Is GridView2.SelectedRow Then

' Textbox1 is the ID for ModifiedBy data field - here I am putting current
user info in the ModifiedBy column to be updated
Dim CurrentUser As TextBox =
CType(GridView2.FindControl("TextBox1"), TextBox)
CurrentUser.Text = Right(User.Identity.Name.ToString,
Len(User.Identity.Name.ToString) - 11)

' Textbox2 is the ID for ModifiedDate data field - here I am putting current
date and time info in the ModifiedDate column to be updated
Dim CurrentDateTime As TextBox =
CType(GridView2.FindControl("TextBox2"), TextBox)
CurrentDateTime.Text = Now().ToShortDateString & " " &
Now().ToShortTimeString

End If
End Sub

****************

ONLY THE FIRST TIME, the following works:
SqlDataSource5.UpdateParameters("ModifiedBy").DefaultValue =
Right(User.Identity.Name.ToString, Len(User.Identity.Name.ToString) - 11)

SqlDataSource5.UpdateParameters("ModifiedDate").DefaultValue =
Now.ToString()

I need the modifiedby and modifiedDate to change every time Update button is
pressed, reflecting current relevant info. This is not happening - please
help if you can

Thanks

JayD
 
Joined
Aug 28, 2009
Messages
1
Reaction score
0
is there a solution?

I'm looking to do the same thing and have tried to many different things and its still not working..

I'm using asp.net 2 VB.net.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top