Hey thanks, this is starting to become a really crazy challenge for him, bumping head against the wall fustration; any ideas or suggestions on getting the other events working. Here's his reply and code.
I added gv1_RowUpating, gv2_RowUpdating, gv1_RowUpdated, and gv2_RowUpdated.
However it still doesn't seem like the update is being triggered. When I click update the new value is replaced by the old value and the gridview stays in edit mode.
Do I need to rebind the gridview or is there something else I'm missing?
Thanks!
Aspx.vb code:
Code:
Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
MyBase.OnInit(e)
Dim sqlconn As New SqlConnection(WebConfigurationManager.ConnectionStrings("ConnectionString").ToString)
Dim cmdExpr As SqlCommand
Dim strSQL As String
Dim myReader As SqlDataReader
Dim id As Integer = 1
strSQL = "Select * from sometable"
cmdExpr = New SqlCommand(strSQL, sqlconn)
sqlconn.Open()
myReader = cmdExpr.ExecuteReader
While myReader.Read
' Create the tab panel's content container and creates the table inside the tab content
Dim tabContent, table As New Control()
Dim tab As New AjaxControlToolkit.TabPanel()
tab.ID = "tabPanel" + id
tab.HeaderText = "Text"
Dim tbl As New Table()
Dim label As New Label()
Dim gv1, gv2 As New GridView()
AddHandler gv1.RowEditing, AddressOf gv1_RowEditing
AddHandler gv1.RowUpdating, AddressOf gv1_RowUpdating
AddHandler gv1.RowUpdated, AddressOf gv1_RowUpdated
AddHandler gv2.RowEditing, AddressOf gv2_RowEditing
AddHandler gv2.RowUpdating, AddressOf gv2_RowUpdating
AddHandler gv2.RowUpdated, AddressOf gv2_RowUpdated
Dim sdsold, sdsnew As New SqlDataSource()
sdsold.ConnectionString = WebConfigurationManager.ConnectionStrings("ConnectionString").ToString
sdsnew.ConnectionString = WebConfigurationManager.ConnectionStrings("ConnectionString").ToString
sdsold.ID = "sdsOld" + id
sdsnew.ID = "sdsNew" + id
sdsnew.SelectCommand = "Select * from table1"
sdsold.SelectCommand = "Select * from table2"
gv1.EmptyDataText = "No record(s) exist"
gv1.ID = "GV1" + id
gv1.Attributes.Add("runat", "server")
'Add Values to the editRowCommand
gv1.Attributes.Add("onRowEditing", "Values go here")
gv1.DataSourceID = sdsnew.ID
gv1.Visible = True
gv1.AutoGenerateEditButton = True
gv2.ID = "GV2" + id
gv2.EmptyDataText = "No record(s) exist"
gv2.Attributes.Add("runat", "server")
'Add Values to the editRowCommand
gv2.Attributes.Add("onRowEditing", "Values go here")
gv2.DataSourceID = sdsold.ID
gv2.Visible = True
gv2.AutoGenerateEditButton = True
' Create Table
Dim tr As New TableRow()
' Create column 1
Dim td1 As New TableCell()
td1.Controls.Add(gv2)
' Create column 2
Dim td2 As New TableCell()
' Add control to the table cell
td2.Controls.Add(gv1)
' Add cell to the row
tr.Cells.Add(td1)
tr.Cells.Add(td2)
' Add row to the table.
tbl.Rows.Add(tr)
tabContent.Controls.Add(label)
table.Controls.Add(tbl)
table.Controls.Add(sdsnew)
table.Controls.Add(sdsold)
tab.Controls.Add(tabContent)
tab.Controls.Add(table)
Me.TabContainer1.Tabs.Add(tab)
gv1.DataBind()
gv2.DataBind()
id += 1
End While
sqlconn.Close()
'Set active tab index
Me.TabContainer1.ActiveTabIndex = 0
End Sub
Protected Sub gv1_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
'cast gridview to get values
Dim tempGrid As GridView = DirectCast(sender, GridView)
tempGrid.EditIndex = e.NewEditIndex
End Sub
Protected Sub gv2_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
'cast gridview to get values
Dim tempGrid As GridView = DirectCast(sender, GridView)
tempGrid.EditIndex = e.NewEditIndex
End Sub
Protected Sub gv1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
Dim tempGrid As GridView = DirectCast(sender, GridView)
Label1.Text = "NEW: " & e.NewValues.Item(1) & "OLD: " & e.OldValues.Item(1)
End Sub
Protected Sub gv2_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
Dim tempGrid As GridView = DirectCast(sender, GridView)
Label1.Text = "NEW: " & e.NewValues.Item(1) & "OLD: " & e.OldValues.Item(1)
End Sub
Protected Sub gv2_RowUpdated(ByVal sender As Object, ByVal e As GridViewUpdatedEventArgs)
Dim tempGrid As GridView = DirectCast(sender, GridView)
Label1.Text = "NEW: " & e.NewValues.Item(1) & "OLD: " & e.OldValues.Item(1)
End Sub
Protected Sub gv1_RowUpdated(ByVal sender As Object, ByVal e As GridViewUpdatedEventArgs)
Dim tempGrid As GridView = DirectCast(sender, GridView)
Label1.Text = "NEW: " & e.NewValues.Item(1) & "OLD: " & e.OldValues.Item(1)
End Sub

Originally Posted by
jmurrayhead
Indeed, if you can get RowEditing working, you should be able to get the other events working

Bookmarks