DataGrid won't Cancel or Update

Discussion in 'ASP .Net Datagrid Control' started by Robert McPherson, Jan 11, 2005.

  1. 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
    Robert McPherson, Jan 11, 2005
    #1
    1. Advertising

  2. Robert McPherson

    Guest

    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
    , Jan 12, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U3RldmUgS2FsbGFs?=

    CssClass on DataGrid Edit, Update & Cancel buttons

    =?Utf-8?B?U3RldmUgS2FsbGFs?=, Jul 6, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    719
    =?Utf-8?B?U3RldmUgS2FsbGFs?=
    Jul 6, 2004
  2. Lucas Tam
    Replies:
    1
    Views:
    465
    Lucas Tam
    Jul 30, 2004
  3. Craig G
    Replies:
    2
    Views:
    659
    Patrick Olurotimi Ige
    Dec 14, 2004
  4. =?Utf-8?B?cG11ZA==?=

    CANT see EDIT UPDATE CANCEL Buttons for DATAGRID

    =?Utf-8?B?cG11ZA==?=, Dec 28, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,386
    =?Utf-8?B?cG11ZA==?=
    Dec 28, 2004
  5. Replies:
    2
    Views:
    550
Loading...

Share This Page