newbie gridview question - how to autoupdate a field

M

Mark

I have a newbie question. I am showing the grid control bound to my database, but I want to automatically update a "last changed by" field whenever someone updates a record. I tried adding onrowupdated="GridView_RowUpdated" to the gridview definition and then the following code but it just returns an error.

<script language="VB" runat=server>
Sub GridView_RowUpdated(ByVal sender As Object, ByVal e As GridViewUpdatedEventArgs)
' finish the update process
sqlCmd = "Update RefInfo set LastChangeID = ChangerID
End Sub
</script>


I also tried adding in the change to the "UpdateCommand" as:
UpdateCommand="Update RefInfo SET
ServerTypeDesc=@ServerTypeDesc,
LastChangeID=ChangerID,
WHERE ServerType=@ServerType">

but that just gives me an error as well. Can someone point out the proper way to do this?
Mark




Base code:

<%@ page language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>Simple GridView display of the REFINFO database</title>
</head>
<body>
<%
dim ChangerID
ChangerID = Request.ServerVariables("LOGON_USER")
%>

<asp:SqlDataSource ID="RWRefInfoDB" runat="server"
ConnectionString="<%$ ConnectionStrings:RWSqlConnectionString %>"
SelectCommand="SELECT * FROM REFINFO"
UpdateCommand="Update RefInfo SET
ServerTypeDesc=@ServerTypeDesc,
WHERE ServerType=@ServerType">
</asp:SqlDataSource>

<form id="form1" runat="server">
<asp:GridView
ID="GridView"
DataSourceID="RWRefInfoDB"
runat="server"
AutoGenerateColumns="False"
AutoGenerateEditButton="True">
<columns>
<asp:BoundField DataField="ServerType" HeaderText="Type" />
<asp:BoundField DataField="ServerTypeDesc" HeaderText="Server Type Long Name" />
</columns>
</asp:GridView>
</form>
</body>
</html>
 
M

Manish

Hi Mark,

Could you please let me know where this ChangeID coming from because you can
select any of the option for the ChangeID parameter where it is coming from
like control, Querystring and all.

Regards,
Manish
www.ComponentOne.com
 
M

Mark

Manish,
I am just writing code in notepad to do all of this.
The variable ChangerID is the logon credentials of the person visiting the
website. It is extracted at the top of the code via the ASP code:
ChangerID = Request.ServerVariables("LOGON_USER")

essentially I want to put into the database the id of whoever made the
change but I can't figure out how to code the GridView so that when someone
updates something it not only updates the data table with the changes made
via the gridview but also the variable.

any help would be greatly appreciated!
Mark
 

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,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top