DataGrid won't Cancel or Update

R

Robert McPherson

I am new to .net so please be patient. I am trying to pass
information between two pages. I need the value to be passed into the
second page in order to populate the datagrid. When I do this I can
click on the Edit button for inline edting and I get the control box's
but I cannot fire the Cancel or Update events. If I auto generate the
columns it works? I have the onEditCommand and OnCancelCommand etc
all pointing at the correct handlers. I have this working in other
pages. Can somebody please help me here?


Public Class Edit_OptionPack
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "
Dim myConnection As New System.Data.SqlClient.SqlConnection("Data
Source=SBSAKHURST;" & _
"Initial
Catalog=QuoteDB;" & _
"User ID=XXXXX;" & _
"Password=XXXXXX")

Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Dim fp As Basefrom
Dim suppDS = New DataSet
Protected WithEvents DataGrid1 As
System.Web.UI.WebControls.DataGrid
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox



<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub


'NOTE: The following placeholder declaration is required by the
Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not (Page.IsPostBack) Then
fp = CType(Context.Handler, Basefrom)
TextBox1.Text = fp.PackA
End If
FillDataGrid()
End Sub
Sub FillDataGrid(Optional ByVal EditIndex As Integer = -1)
Dim selectSQL As String = ("SELECT *, TblMachOpt.OptPackID,
TblOptList.OptionCode FROM TblMachOpt INNER JOIN TblOptList ON
TblMachOpt.OptID = TblOptList.OptID WHERE (TblMachOpt.OptPackID =
@oID)")
Dim custDA As System.Data.SqlClient.SqlDataAdapter = New
SqlClient.SqlDataAdapter
Dim selectCMD As New SqlClient.SqlCommand(selectSQL,
myConnection)
custDA.SelectCommand = selectCMD
selectCMD.Parameters.Add("@oID", SqlDbType.Char, 15).Value =
TextBox1.Text
Dim custDS = New DataSet
custDA.Fill(custDS, "TblMachOpt")
DataGrid1.DataSource = custDS.Tables("TblMachOpt").DefaultView
Page.DataBind()
myConnection.Close()
End Sub
Sub DataGrid1_Edit(ByVal Sender As Object, ByVal e As
DataGridCommandEventArgs)
DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()
End Sub
Sub DataGrid1_Update(ByVal Sender As Object, ByVal e As
DataGridCommandEventArgs)
Dim params(7) As String
Dim strText As String
Dim strID As String
Dim myDate As Date
Dim blngo As Boolean = True
strText = CType(e.Item.Cells(4).Controls(0), TextBox).Text
strID = e.Item.Cells(0).Text
myDate = Today
Dim strSQL As String = "UPDATE TblExcRateOpt SET ExcRate ='" &
strText & "', Date='" & myDate & "' WHERE ExchOptID =" & strID
DataGrid1.EditItemIndex = -1
FillDataGrid()
End Sub
Sub DataGrid1_Cancel(ByVal Sender As Object, ByVal e As
DataGridCommandEventArgs)
DataGrid1.EditItemIndex() = -1
FillDataGrid()
End Sub
Function ExecuteStatement(ByVal strSQL)
Dim objCmd As New SqlClient.SqlCommand(strSQL, myConnection)
Dim err As ErrObject
Try
objCmd.Connection.Open()
objCmd.ExecuteNonQuery()
Catch ex As Exception
'lblMessage.Text = "Could Not Update"
End Try
objCmd.Connection.Close()
'lblMessage.Text = "Change Sucessful"
FillDataGrid()
End Function
End Class
 
L

linhardt

Robert,

Looks like you don't have your handlers set up correctly:

Sub DataGrid1_Update(ByVal Sender As Object, ByVal e As
DataGridCommandEventArgs)

Should look more like:

Sub DataGrid1_Update(ByVal Sender As Object, ByVal e As
DataGridCommandEventArgs) Handles DataGrid1.CancelCommand

Ditto for the other handlers.

If that still doesn't work, but breakpoints on your handlers to see if
they are being tripped or not.

-Paul
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top