473,382 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

gridview update programatically

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").Defa ultValue =
Right(User.Identity.Name.ToString, Len(User.Identity.Name.ToString) - 11)

SqlDataSource5.UpdateParameters("ModifiedDate").De faultValue =
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
Sep 7 '06 #1
0 3346

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: MasterChief | last post by:
Is it possible to select an item on a gridview by clicking on it and then being able to click a link for example that says EditOrder in a treeview and have the EditOrder page open up viewing what...
3
by: misiek | last post by:
Hi all. I have following problem: 1. In my web page I have a GridView control, which does not have a DataSourceId set in designer. 2. When user presses Start button then I create...
2
by: luisxx | last post by:
WinSrv2003 SP1 IIS 6.0 ASP.NET C#, 2.0 SQL 2005 All on same machine Hello everyone! I have a method in ASP.NET 2.0 that I can't seem to get right, Gridview1_rowcommand.
2
by: nolan | last post by:
I have an asp.net 2.0 page with a gridview and detailsview on the same page set up in a master-details scenario. The gridview and detailsview have separate SQL data sources. The user enters...
6
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the...
2
by: Gerhard | last post by:
How can I set a row in a gridview programatically to edit mode (rather than having to have the user click the edit row command), so the fields can be edited and the Update and Cancel buttons...
3
by: =?Utf-8?B?bWFuaWthMDI=?= | last post by:
Hi, I have a GridView control in page called eventslisting which is inheriting from a MasterPage. The normal code to export to GridView does not work and gives me an error - "Control of type...
4
by: Tomasz | last post by:
Hello Developers, Here is interesting problem I just came across: how do I wire a GridView control programmatically? Here is my sample code using Object Data Source: protected void...
4
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.