Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > DataGrid won't Cancel or Update

Reply
Thread Tools

DataGrid won't Cancel or Update

 
 
Robert McPherson
Guest
Posts: n/a
 
      01-11-2005
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
 
Reply With Quote
 
 
 
 
linhardt@aol.com
Guest
Posts: n/a
 
      01-12-2005
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

Robert McPherson wrote:
> 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?
>
>
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP CANCEL CANCEL CANCEL Carmen Rosario Computer Support 7 04-06-2005 11:04 PM
CANT see EDIT UPDATE CANCEL Buttons for DATAGRID =?Utf-8?B?cG11ZA==?= ASP .Net 3 12-28-2004 04:07 PM
applying CssClass to Edit/Update/Cancel button in Datagrid Craig G ASP .Net 2 12-14-2004 12:19 PM
Dynamically Created DataGrid's Cancel/Update Button Not firing Lucas Tam ASP .Net 1 07-30-2004 04:33 PM
CssClass on DataGrid Edit, Update & Cancel buttons =?Utf-8?B?U3RldmUgS2FsbGFs?= ASP .Net 0 07-06-2004 04:59 PM



Advertisments