Event Handler for GridView RowUpdating

evad4682

Well-known member
Joined
Nov 7, 2005
Messages
55
Programming Experience
Beginner
I am struggling to figure out how to create an event handler for RowUpdating. I am using Visual Web Developer Express 2005 .NET 2.0.
I can't use the wizard because my GridView displays a custom query that joins several database tables. From what I am finding online I need to build a sub routine and then point the RowUpdating Event in the properties pane of my GridView to that sub routine. How do I do this? This is what I am thinking.
VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] update([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] GridViewUpdatedEventHandler)
[/SIZE][SIZE=2][COLOR=#008000]'How do I know what row in the GridView I have selected?
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'I need to update my database table based on a column value that is in the 
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'row I have selected.
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] query [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"UPDATE table SET values columnName1 = '1' WHERE columnName2 = '"[/COLOR][/SIZE][SIZE=2] & value from GridView
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objcommand10 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Data.SqlClient.SqlCommand(query, [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Data.SqlClient.SqlConnection(cnxn))
objcommand10.Connection.Open()
objcommand10.ExecuteNonQuery()
objcommand10.Connection.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]

???

Thanks Everyone!

Side note - What is the difference between RowUpdating and RowUpdated?
 
Top Bottom