Cancel does Delete instead!??

Discussion in 'ASP .Net Datagrid Control' started by cj, May 10, 2005.

  1. cj

    cj Guest

    I have created a datagrid with both EditCommandColumn and ButtonColumn
    (setup as Delete). Even when I change the Delete command to a different name
    "Remove", the "Cancel" button always ends up doing the 'Delete/Remove'
    subroutine :(

    What is happening with this? I searched on the net and only found one
    similar occurance, but no answer :( Surely it is a known problem..?

    Below is some of my code.

    Any help out there (I've spent hours trying to nut this out...)?

    Thanks

    cj

    <asp:datagrid
    id="dgSoldItems"
    runat="server"
    AutoGenerateColumns="False"
    EnableViewState="False"
    ForeColor="Black"
    BackColor="White"
    CellPadding="3"
    CellSpacing="1"
    Font-Size="X-Small"
    GridLines="None"
    DataKeyField="SaleItemID"
    OnEditCommand="dgSoldItems_Edit"
    OnCancelCommand="dgSoldItems_Cancel"
    OnUpdateCommand="dgSoldItems_Update"
    OnDeleteCommand="dgSoldItems_Delete"
    >

    <ItemStyle
    backcolor="#DEDFDE"></ItemStyle>
    <HeaderStyle font-bold="True"
    forecolor="White" backcolor="#4A3C8C"></HeaderStyle>
    <Columns>
    <asp:EditCommandColumn
    EditText="Edit" CancelText="Cancel" UpdateText="Update"
    ItemStyle-Wrap="false" ButtonType="PushButton"/>
    <asp:ButtonColumn Text="Remove Item"
    CommandName="Delete" ButtonType="PushButton"/>
    <asp:BoundColumn DataField="ItemID"
    HeaderText="Item ID" ReadOnly="True"></asp:BoundColumn>
    <asp:BoundColumn DataField="Price"
    HeaderText="Price" DataFormatString="{0:c}"></asp:BoundColumn>
    <asp:BoundColumn
    DataField="ProductName" HeaderText="Product Name"
    ReadOnly="True"></asp:BoundColumn>
    <asp:BoundColumn
    DataField="ModelNumber" HeaderText="Model Number"
    ReadOnly="True"></asp:BoundColumn>
    <asp:BoundColumn
    DataField="SerialNumber" HeaderText="Serial Number"
    ReadOnly="True"></asp:BoundColumn>
    <asp:BoundColumn
    DataField="AssetNumber" HeaderText="Asset Number"
    ReadOnly="True"></asp:BoundColumn>
    <asp:BoundColumn DataField="SaleID"
    HeaderText="SaleID" ReadOnly="True"></asp:BoundColumn>
    <asp:BoundColumn
    DataField="SaleItemID" HeaderText="SaleItemID"
    ReadOnly="True"></asp:BoundColumn>
    </Columns>
    </asp:datagrid>

    Sub dgSoldItems_Edit(Sender As Object, E As DataGridCommandEventArgs)
    dgSoldItems.EditItemIndex = CInt(E.Item.ItemIndex)
    BinddgSoldItems()
    End Sub

    Sub dgSoldItems_Cancel(Sender As Object, E As DataGridCommandEventArgs)
    dgSoldItems.EditItemIndex = -1
    BinddgSoldItems()
    End Sub

    Sub dgSoldItems_Update(Sender As Object, E As DataGridCommandEventArgs)
    End Sub

    Sub dgSoldItems_Delete(Sender As Object, E As DataGridCommandEventArgs)

    Dim DelItemCommand As SqlCommand
    Dim DeleteCmdText As String = "DELETE from Sold_Items where
    SaleItemID = @SaleItemID"

    DelItemCommand = New SqlCommand(DeleteCmdText, MyConnection)

    Dim dbParam_SaleItemID As System.Data.IDataParameter = New
    System.Data.SqlClient.SqlParameter
    dbParam_SaleItemID.ParameterName = "@SaleItemID"
    dbParam_SaleItemID.Value =
    dgSoldItems.DataKeys(CInt(E.Item.ItemIndex))
    dbParam_SaleItemID.DbType = System.Data.DbType.Int32
    DelItemCommand.Parameters.Add(dbParam_SaleItemID)

    DelItemCommand.Connection.Open()

    Try
    DelItemCommand.ExecuteNonQuery()
    lblmsg.Text = "<b>Record [SaleItemID=" &
    dgSoldItems.DataKeys(CInt(E.Item.ItemIndex)) & "] Deleted</b>"
    Catch Exc As SQLException
    lblmsg.Text = "ERROR: Could not delete record"
    End Try

    DelItemCommand.Connection.Close()

    BinddgSoldItems()
    End Sub
     
    cj, May 10, 2005
    #1
    1. Advertising

  2. cj

    cj Guest

    Actually, my problem looks similar/same as Bruce. E. Bonsall ("Dynamic
    EditCommandColumn events") who posted earlier today.. but still no answer...

    Thanks

    cj


    "cj" <> wrote in message
    news:428034d8$0$259$...
    >I have created a datagrid with both EditCommandColumn and ButtonColumn
    >(setup as Delete). Even when I change the Delete command to a different
    >name "Remove", the "Cancel" button always ends up doing the 'Delete/Remove'
    >subroutine :(
    >
    > What is happening with this? I searched on the net and only found one
    > similar occurance, but no answer :( Surely it is a known problem..?
    >
    > Below is some of my code.
    >
    > Any help out there (I've spent hours trying to nut this out...)?
    >
    > Thanks
    >
    > cj
    >
    > <asp:datagrid
    > id="dgSoldItems"
    > runat="server"
    > AutoGenerateColumns="False"
    > EnableViewState="False"
    > ForeColor="Black"
    > BackColor="White"
    > CellPadding="3"
    > CellSpacing="1"
    > Font-Size="X-Small"
    > GridLines="None"
    > DataKeyField="SaleItemID"
    > OnEditCommand="dgSoldItems_Edit"
    > OnCancelCommand="dgSoldItems_Cancel"
    > OnUpdateCommand="dgSoldItems_Update"
    > OnDeleteCommand="dgSoldItems_Delete"
    > >

    > <ItemStyle
    > backcolor="#DEDFDE"></ItemStyle>
    > <HeaderStyle font-bold="True"
    > forecolor="White" backcolor="#4A3C8C"></HeaderStyle>
    > <Columns>
    > <asp:EditCommandColumn
    > EditText="Edit" CancelText="Cancel" UpdateText="Update"
    > ItemStyle-Wrap="false" ButtonType="PushButton"/>
    > <asp:ButtonColumn Text="Remove
    > Item" CommandName="Delete" ButtonType="PushButton"/>
    > <asp:BoundColumn DataField="ItemID"
    > HeaderText="Item ID" ReadOnly="True"></asp:BoundColumn>
    > <asp:BoundColumn DataField="Price"
    > HeaderText="Price" DataFormatString="{0:c}"></asp:BoundColumn>
    > <asp:BoundColumn
    > DataField="ProductName" HeaderText="Product Name"
    > ReadOnly="True"></asp:BoundColumn>
    > <asp:BoundColumn
    > DataField="ModelNumber" HeaderText="Model Number"
    > ReadOnly="True"></asp:BoundColumn>
    > <asp:BoundColumn
    > DataField="SerialNumber" HeaderText="Serial Number"
    > ReadOnly="True"></asp:BoundColumn>
    > <asp:BoundColumn
    > DataField="AssetNumber" HeaderText="Asset Number"
    > ReadOnly="True"></asp:BoundColumn>
    > <asp:BoundColumn DataField="SaleID"
    > HeaderText="SaleID" ReadOnly="True"></asp:BoundColumn>
    > <asp:BoundColumn
    > DataField="SaleItemID" HeaderText="SaleItemID"
    > ReadOnly="True"></asp:BoundColumn>
    > </Columns>
    > </asp:datagrid>
    >
    > Sub dgSoldItems_Edit(Sender As Object, E As DataGridCommandEventArgs)
    > dgSoldItems.EditItemIndex = CInt(E.Item.ItemIndex)
    > BinddgSoldItems()
    > End Sub
    >
    > Sub dgSoldItems_Cancel(Sender As Object, E As DataGridCommandEventArgs)
    > dgSoldItems.EditItemIndex = -1
    > BinddgSoldItems()
    > End Sub
    >
    > Sub dgSoldItems_Update(Sender As Object, E As DataGridCommandEventArgs)
    > End Sub
    >
    > Sub dgSoldItems_Delete(Sender As Object, E As DataGridCommandEventArgs)
    >
    > Dim DelItemCommand As SqlCommand
    > Dim DeleteCmdText As String = "DELETE from Sold_Items where
    > SaleItemID = @SaleItemID"
    >
    > DelItemCommand = New SqlCommand(DeleteCmdText, MyConnection)
    >
    > Dim dbParam_SaleItemID As System.Data.IDataParameter = New
    > System.Data.SqlClient.SqlParameter
    > dbParam_SaleItemID.ParameterName = "@SaleItemID"
    > dbParam_SaleItemID.Value =
    > dgSoldItems.DataKeys(CInt(E.Item.ItemIndex))
    > dbParam_SaleItemID.DbType = System.Data.DbType.Int32
    > DelItemCommand.Parameters.Add(dbParam_SaleItemID)
    >
    > DelItemCommand.Connection.Open()
    >
    > Try
    > DelItemCommand.ExecuteNonQuery()
    > lblmsg.Text = "<b>Record [SaleItemID=" &
    > dgSoldItems.DataKeys(CInt(E.Item.ItemIndex)) & "] Deleted</b>"
    > Catch Exc As SQLException
    > lblmsg.Text = "ERROR: Could not delete record"
    > End Try
    >
    > DelItemCommand.Connection.Close()
    >
    > BinddgSoldItems()
    > End Sub
    >
    >
    >
     
    cj, May 10, 2005
    #2
    1. Advertising

  3. cj

    Elton W Guest

    Hi CJ,

    Change the datagrid's EnableViewState from false to true.
    Although disabled viewstate can improve performance of the
    datagrid, it also causes many functionalities not work
    properly.

    HTH

    Elton Wang



    >-----Original Message-----
    >Actually, my problem looks similar/same as Bruce. E.

    Bonsall ("Dynamic
    >EditCommandColumn events") who posted earlier today.. but

    still no answer...
    >
    >Thanks
    >
    >cj
    >
    >
    >"cj" <> wrote in message
    >news:428034d8$0$259$61c65585@uq-127creek-reader-

    03.brisbane.pipenetworks.com.au...
    >>I have created a datagrid with both EditCommandColumn

    and ButtonColumn
    >>(setup as Delete). Even when I change the Delete command

    to a different
    >>name "Remove", the "Cancel" button always ends up doing

    the 'Delete/Remove'
    >>subroutine :(
    >>
    >> What is happening with this? I searched on the net and

    only found one
    >> similar occurance, but no answer :( Surely it is a

    known problem..?
    >>
    >> Below is some of my code.
    >>
    >> Any help out there (I've spent hours trying to nut this

    out...)?
    >>
    >> Thanks
    >>
    >> cj
    >>
    >> <asp:datagrid
    >> id="dgSoldItems"
    >> runat="server"
    >>

    AutoGenerateColumns="False"
    >>

    EnableViewState="False"
    >> ForeColor="Black"
    >> BackColor="White"
    >> CellPadding="3"
    >> CellSpacing="1"
    >> Font-Size="X-Small"
    >> GridLines="None"
    >>

    DataKeyField="SaleItemID"
    >>

    OnEditCommand="dgSoldItems_Edit"
    >>

    OnCancelCommand="dgSoldItems_Cancel"
    >>

    OnUpdateCommand="dgSoldItems_Update"
    >>

    OnDeleteCommand="dgSoldItems_Delete"
    >> >

    >> <ItemStyle
    >> backcolor="#DEDFDE"></ItemStyle>
    >> <HeaderStyle font-

    bold="True"
    >> forecolor="White" backcolor="#4A3C8C"></HeaderStyle>
    >> <Columns>
    >>

    <asp:EditCommandColumn
    >> EditText="Edit" CancelText="Cancel" UpdateText="Update"
    >> ItemStyle-Wrap="false" ButtonType="PushButton"/>
    >>

    <asp:ButtonColumn Text="Remove
    >> Item" CommandName="Delete" ButtonType="PushButton"/>
    >> <asp:BoundColumn

    DataField="ItemID"
    >> HeaderText="Item ID" ReadOnly="True"></asp:BoundColumn>
    >> <asp:BoundColumn

    DataField="Price"
    >> HeaderText="Price"

    DataFormatString="{0:c}"></asp:BoundColumn>
    >> <asp:BoundColumn
    >> DataField="ProductName" HeaderText="Product Name"
    >> ReadOnly="True"></asp:BoundColumn>
    >> <asp:BoundColumn
    >> DataField="ModelNumber" HeaderText="Model Number"
    >> ReadOnly="True"></asp:BoundColumn>
    >> <asp:BoundColumn
    >> DataField="SerialNumber" HeaderText="Serial Number"
    >> ReadOnly="True"></asp:BoundColumn>
    >> <asp:BoundColumn
    >> DataField="AssetNumber" HeaderText="Asset Number"
    >> ReadOnly="True"></asp:BoundColumn>
    >> <asp:BoundColumn

    DataField="SaleID"
    >> HeaderText="SaleID" ReadOnly="True"></asp:BoundColumn>
    >> <asp:BoundColumn
    >> DataField="SaleItemID" HeaderText="SaleItemID"
    >> ReadOnly="True"></asp:BoundColumn>
    >> </Columns>
    >> </asp:datagrid>
    >>
    >> Sub dgSoldItems_Edit(Sender As Object, E As

    DataGridCommandEventArgs)
    >> dgSoldItems.EditItemIndex = CInt(E.Item.ItemIndex)
    >> BinddgSoldItems()
    >> End Sub
    >>
    >> Sub dgSoldItems_Cancel(Sender As Object, E As

    DataGridCommandEventArgs)
    >> dgSoldItems.EditItemIndex = -1
    >> BinddgSoldItems()
    >> End Sub
    >>
    >> Sub dgSoldItems_Update(Sender As Object, E As

    DataGridCommandEventArgs)
    >> End Sub
    >>
    >> Sub dgSoldItems_Delete(Sender As Object, E As

    DataGridCommandEventArgs)
    >>
    >> Dim DelItemCommand As SqlCommand
    >> Dim DeleteCmdText As String = "DELETE from

    Sold_Items where
    >> SaleItemID = @SaleItemID"
    >>
    >> DelItemCommand = New SqlCommand

    (DeleteCmdText, MyConnection)
    >>
    >> Dim dbParam_SaleItemID As

    System.Data.IDataParameter = New
    >> System.Data.SqlClient.SqlParameter
    >> dbParam_SaleItemID.ParameterName = "@SaleItemID"
    >> dbParam_SaleItemID.Value =
    >> dgSoldItems.DataKeys(CInt(E.Item.ItemIndex))
    >> dbParam_SaleItemID.DbType =

    System.Data.DbType.Int32
    >> DelItemCommand.Parameters.Add(dbParam_SaleItemID)
    >>
    >> DelItemCommand.Connection.Open()
    >>
    >> Try
    >> DelItemCommand.ExecuteNonQuery()
    >> lblmsg.Text = "<b>Record [SaleItemID=" &
    >> dgSoldItems.DataKeys(CInt(E.Item.ItemIndex)) & "]

    Deleted</b>"
    >> Catch Exc As SQLException
    >> lblmsg.Text = "ERROR: Could not delete

    record"
    >> End Try
    >>
    >> DelItemCommand.Connection.Close()
    >>
    >> BinddgSoldItems()
    >> End Sub
    >>
    >>
    >>

    >
    >
    >.
    >
     
    Elton W, May 10, 2005
    #3
  4. cj

    cj Guest

    When I did that, none of the buttons worked at all (neither Edit or Remove).

    cj

    "Elton W" <> wrote in message
    news:115401c55559$cce72d80$...
    > Hi CJ,
    >
    > Change the datagrid's EnableViewState from false to true.
    > Although disabled viewstate can improve performance of the
    > datagrid, it also causes many functionalities not work
    > properly.
    >
    > HTH
    >
    > Elton Wang
    >
    >
    >
    >>-----Original Message-----
    >>Actually, my problem looks similar/same as Bruce. E.

    > Bonsall ("Dynamic
    >>EditCommandColumn events") who posted earlier today.. but

    > still no answer...
    >>
    >>Thanks
    >>
    >>cj
    >>
    >>
    >>"cj" <> wrote in message
    >>news:428034d8$0$259$61c65585@uq-127creek-reader-

    > 03.brisbane.pipenetworks.com.au...
    >>>I have created a datagrid with both EditCommandColumn

    > and ButtonColumn
    >>>(setup as Delete). Even when I change the Delete command

    > to a different
    >>>name "Remove", the "Cancel" button always ends up doing

    > the 'Delete/Remove'
    >>>subroutine :(
    >>>
    >>> What is happening with this? I searched on the net and

    > only found one
    >>> similar occurance, but no answer :( Surely it is a

    > known problem..?
    >>>
    >>> Below is some of my code.
    >>>
    >>> Any help out there (I've spent hours trying to nut this

    > out...)?
    >>>
    >>> Thanks
    >>>
    >>> cj
    >>>
    >>> <asp:datagrid
    >>> id="dgSoldItems"
    >>> runat="server"
    >>>

    > AutoGenerateColumns="False"
    >>>

    > EnableViewState="False"
    >>> ForeColor="Black"
    >>> BackColor="White"
    >>> CellPadding="3"
    >>> CellSpacing="1"
    >>> Font-Size="X-Small"
    >>> GridLines="None"
    >>>

    > DataKeyField="SaleItemID"
    >>>

    > OnEditCommand="dgSoldItems_Edit"
    >>>

    > OnCancelCommand="dgSoldItems_Cancel"
    >>>

    > OnUpdateCommand="dgSoldItems_Update"
    >>>

    > OnDeleteCommand="dgSoldItems_Delete"
    >>> >
    >>> <ItemStyle
    >>> backcolor="#DEDFDE"></ItemStyle>
    >>> <HeaderStyle font-

    > bold="True"
    >>> forecolor="White" backcolor="#4A3C8C"></HeaderStyle>
    >>> <Columns>
    >>>

    > <asp:EditCommandColumn
    >>> EditText="Edit" CancelText="Cancel" UpdateText="Update"
    >>> ItemStyle-Wrap="false" ButtonType="PushButton"/>
    >>>

    > <asp:ButtonColumn Text="Remove
    >>> Item" CommandName="Delete" ButtonType="PushButton"/>
    >>> <asp:BoundColumn

    > DataField="ItemID"
    >>> HeaderText="Item ID" ReadOnly="True"></asp:BoundColumn>
    >>> <asp:BoundColumn

    > DataField="Price"
    >>> HeaderText="Price"

    > DataFormatString="{0:c}"></asp:BoundColumn>
    >>> <asp:BoundColumn
    >>> DataField="ProductName" HeaderText="Product Name"
    >>> ReadOnly="True"></asp:BoundColumn>
    >>> <asp:BoundColumn
    >>> DataField="ModelNumber" HeaderText="Model Number"
    >>> ReadOnly="True"></asp:BoundColumn>
    >>> <asp:BoundColumn
    >>> DataField="SerialNumber" HeaderText="Serial Number"
    >>> ReadOnly="True"></asp:BoundColumn>
    >>> <asp:BoundColumn
    >>> DataField="AssetNumber" HeaderText="Asset Number"
    >>> ReadOnly="True"></asp:BoundColumn>
    >>> <asp:BoundColumn

    > DataField="SaleID"
    >>> HeaderText="SaleID" ReadOnly="True"></asp:BoundColumn>
    >>> <asp:BoundColumn
    >>> DataField="SaleItemID" HeaderText="SaleItemID"
    >>> ReadOnly="True"></asp:BoundColumn>
    >>> </Columns>
    >>> </asp:datagrid>
    >>>
    >>> Sub dgSoldItems_Edit(Sender As Object, E As

    > DataGridCommandEventArgs)
    >>> dgSoldItems.EditItemIndex = CInt(E.Item.ItemIndex)
    >>> BinddgSoldItems()
    >>> End Sub
    >>>
    >>> Sub dgSoldItems_Cancel(Sender As Object, E As

    > DataGridCommandEventArgs)
    >>> dgSoldItems.EditItemIndex = -1
    >>> BinddgSoldItems()
    >>> End Sub
    >>>
    >>> Sub dgSoldItems_Update(Sender As Object, E As

    > DataGridCommandEventArgs)
    >>> End Sub
    >>>
    >>> Sub dgSoldItems_Delete(Sender As Object, E As

    > DataGridCommandEventArgs)
    >>>
    >>> Dim DelItemCommand As SqlCommand
    >>> Dim DeleteCmdText As String = "DELETE from

    > Sold_Items where
    >>> SaleItemID = @SaleItemID"
    >>>
    >>> DelItemCommand = New SqlCommand

    > (DeleteCmdText, MyConnection)
    >>>
    >>> Dim dbParam_SaleItemID As

    > System.Data.IDataParameter = New
    >>> System.Data.SqlClient.SqlParameter
    >>> dbParam_SaleItemID.ParameterName = "@SaleItemID"
    >>> dbParam_SaleItemID.Value =
    >>> dgSoldItems.DataKeys(CInt(E.Item.ItemIndex))
    >>> dbParam_SaleItemID.DbType =

    > System.Data.DbType.Int32
    >>> DelItemCommand.Parameters.Add(dbParam_SaleItemID)
    >>>
    >>> DelItemCommand.Connection.Open()
    >>>
    >>> Try
    >>> DelItemCommand.ExecuteNonQuery()
    >>> lblmsg.Text = "<b>Record [SaleItemID=" &
    >>> dgSoldItems.DataKeys(CInt(E.Item.ItemIndex)) & "]

    > Deleted</b>"
    >>> Catch Exc As SQLException
    >>> lblmsg.Text = "ERROR: Could not delete

    > record"
    >>> End Try
    >>>
    >>> DelItemCommand.Connection.Close()
    >>>
    >>> BinddgSoldItems()
    >>> End Sub
    >>>
    >>>
    >>>

    >>
    >>
    >>.
    >>
     
    cj, May 10, 2005
    #4
  5. cj

    Elton W Guest

    The event handler should look like

    Private Sub DataGrid1_EditCommand(ByVal source As Object,
    ByVal e As
    System.Web.UI.WebControls.DataGridCommandEventArgs)
    Handles dgSoldItems.EditCommand
    ' Code

    End Sub

    Your code misses something like

    Handles dgSoldItems.EditCommand

    Without these key works, it's just normal method rather
    than event handler.


    HTH

    Elton Wang


    >-----Original Message-----
    >When I did that, none of the buttons worked at all

    (neither Edit or Remove).
    >
    >cj
    >
    >"Elton W" <> wrote in

    message
    >news:115401c55559$cce72d80$...
    >> Hi CJ,
    >>
    >> Change the datagrid's EnableViewState from false to

    true.
    >> Although disabled viewstate can improve performance of

    the
    >> datagrid, it also causes many functionalities not work
    >> properly.
    >>
    >> HTH
    >>
    >> Elton Wang
    >>
    >>
    >>
    >>>-----Original Message-----
    >>>Actually, my problem looks similar/same as Bruce. E.

    >> Bonsall ("Dynamic
    >>>EditCommandColumn events") who posted earlier today..

    but
    >> still no answer...
    >>>
    >>>Thanks
    >>>
    >>>cj
    >>>
    >>>
    >>>"cj" <> wrote in message
    >>>news:428034d8$0$259$61c65585@uq-127creek-reader-

    >> 03.brisbane.pipenetworks.com.au...
    >>>>I have created a datagrid with both EditCommandColumn

    >> and ButtonColumn
    >>>>(setup as Delete). Even when I change the Delete

    command
    >> to a different
    >>>>name "Remove", the "Cancel" button always ends up doing

    >> the 'Delete/Remove'
    >>>>subroutine :(
    >>>>
    >>>> What is happening with this? I searched on the net and

    >> only found one
    >>>> similar occurance, but no answer :( Surely it is a

    >> known problem..?
    >>>>
    >>>> Below is some of my code.
    >>>>
    >>>> Any help out there (I've spent hours trying to nut

    this
    >> out...)?
    >>>>
    >>>> Thanks
    >>>>
    >>>> cj
    >>>>
    >>>> <asp:datagrid
    >>>> id="dgSoldItems"
    >>>> runat="server"
    >>>>

    >> AutoGenerateColumns="False"
    >>>>

    >> EnableViewState="False"
    >>>> ForeColor="Black"
    >>>> BackColor="White"
    >>>> CellPadding="3"
    >>>> CellSpacing="1"
    >>>> Font-Size="X-Small"
    >>>> GridLines="None"
    >>>>

    >> DataKeyField="SaleItemID"
    >>>>

    >> OnEditCommand="dgSoldItems_Edit"
    >>>>

    >> OnCancelCommand="dgSoldItems_Cancel"
    >>>>

    >> OnUpdateCommand="dgSoldItems_Update"
    >>>>

    >> OnDeleteCommand="dgSoldItems_Delete"
    >>>> >
    >>>> <ItemStyle
    >>>> backcolor="#DEDFDE"></ItemStyle>
    >>>> <HeaderStyle font-

    >> bold="True"
    >>>> forecolor="White" backcolor="#4A3C8C"></HeaderStyle>
    >>>> <Columns>
    >>>>

    >> <asp:EditCommandColumn
    >>>> EditText="Edit" CancelText="Cancel"

    UpdateText="Update"
    >>>> ItemStyle-Wrap="false" ButtonType="PushButton"/>
    >>>>

    >> <asp:ButtonColumn Text="Remove
    >>>> Item" CommandName="Delete" ButtonType="PushButton"/>
    >>>>

    <asp:BoundColumn
    >> DataField="ItemID"
    >>>> HeaderText="Item ID"

    ReadOnly="True"></asp:BoundColumn>
    >>>>

    <asp:BoundColumn
    >> DataField="Price"
    >>>> HeaderText="Price"

    >> DataFormatString="{0:c}"></asp:BoundColumn>
    >>>>

    <asp:BoundColumn
    >>>> DataField="ProductName" HeaderText="Product Name"
    >>>> ReadOnly="True"></asp:BoundColumn>
    >>>>

    <asp:BoundColumn
    >>>> DataField="ModelNumber" HeaderText="Model Number"
    >>>> ReadOnly="True"></asp:BoundColumn>
    >>>>

    <asp:BoundColumn
    >>>> DataField="SerialNumber" HeaderText="Serial Number"
    >>>> ReadOnly="True"></asp:BoundColumn>
    >>>>

    <asp:BoundColumn
    >>>> DataField="AssetNumber" HeaderText="Asset Number"
    >>>> ReadOnly="True"></asp:BoundColumn>
    >>>>

    <asp:BoundColumn
    >> DataField="SaleID"
    >>>> HeaderText="SaleID" ReadOnly="True"></asp:BoundColumn>
    >>>>

    <asp:BoundColumn
    >>>> DataField="SaleItemID" HeaderText="SaleItemID"
    >>>> ReadOnly="True"></asp:BoundColumn>
    >>>> </Columns>
    >>>> </asp:datagrid>
    >>>>
    >>>> Sub dgSoldItems_Edit(Sender As Object, E As

    >> DataGridCommandEventArgs)
    >>>> dgSoldItems.EditItemIndex = CInt(E.Item.ItemIndex)
    >>>> BinddgSoldItems()
    >>>> End Sub
    >>>>
    >>>> Sub dgSoldItems_Cancel(Sender As Object, E As

    >> DataGridCommandEventArgs)
    >>>> dgSoldItems.EditItemIndex = -1
    >>>> BinddgSoldItems()
    >>>> End Sub
    >>>>
    >>>> Sub dgSoldItems_Update(Sender As Object, E As

    >> DataGridCommandEventArgs)
    >>>> End Sub
    >>>>
    >>>> Sub dgSoldItems_Delete(Sender As Object, E As

    >> DataGridCommandEventArgs)
    >>>>
    >>>> Dim DelItemCommand As SqlCommand
    >>>> Dim DeleteCmdText As String = "DELETE from

    >> Sold_Items where
    >>>> SaleItemID = @SaleItemID"
    >>>>
    >>>> DelItemCommand = New SqlCommand

    >> (DeleteCmdText, MyConnection)
    >>>>
    >>>> Dim dbParam_SaleItemID As

    >> System.Data.IDataParameter = New
    >>>> System.Data.SqlClient.SqlParameter
    >>>> dbParam_SaleItemID.ParameterName

    = "@SaleItemID"
    >>>> dbParam_SaleItemID.Value =
    >>>> dgSoldItems.DataKeys(CInt(E.Item.ItemIndex))
    >>>> dbParam_SaleItemID.DbType =

    >> System.Data.DbType.Int32
    >>>> DelItemCommand.Parameters.Add

    (dbParam_SaleItemID)
    >>>>
    >>>> DelItemCommand.Connection.Open()
    >>>>
    >>>> Try
    >>>> DelItemCommand.ExecuteNonQuery()
    >>>> lblmsg.Text = "<b>Record [SaleItemID=" &
    >>>> dgSoldItems.DataKeys(CInt(E.Item.ItemIndex)) & "]

    >> Deleted</b>"
    >>>> Catch Exc As SQLException
    >>>> lblmsg.Text = "ERROR: Could not delete

    >> record"
    >>>> End Try
    >>>>
    >>>> DelItemCommand.Connection.Close()
    >>>>
    >>>> BinddgSoldItems()
    >>>> End Sub
    >>>>
    >>>>
    >>>>
    >>>
    >>>
    >>>.
    >>>

    >
    >
    >.
    >
     
    Elton W, May 10, 2005
    #5
  6. cj

    cj Guest

    I was just following the examples at:

    http://samples.gotdotnet.com/quickstart/aspplus/doc/webdataaccess.aspx

    http://samples.gotdotnet.com/quicks...bforms/ctrlref/webctrl/datagrid/datagrid4.src

    Why don't they do the 'handles' thing?

    Also, why does it all work fine without 'viewstate' enabled, as long as I
    only use DELETE (via BUTTONCOLUMN) or only use EDITCOMMANDCOLUMN?

    Thanks

    cj



    "Elton W" <> wrote in message
    news:1b9701c55586$886360c0$...
    > The event handler should look like
    >
    > Private Sub DataGrid1_EditCommand(ByVal source As Object,
    > ByVal e As
    > System.Web.UI.WebControls.DataGridCommandEventArgs)
    > Handles dgSoldItems.EditCommand
    > ' Code
    >
    > End Sub
    >
    > Your code misses something like
    >
    > Handles dgSoldItems.EditCommand
    >
    > Without these key works, it's just normal method rather
    > than event handler.
    >
    >
    > HTH
    >
    > Elton Wang
     
    cj, May 11, 2005
    #6
  7. cj

    Elton W Guest

    Any button in a datagrid, including edit, delete, and so
    on, will fire datagrid_ ItemCommand event. So you can
    build the event in codebehind like follows:

    Private Sub dgSoldItems_ItemCommand(ByVal source As
    Object, ByVal e As
    System.Web.UI.WebControls.DataGridCommandEventArgs)
    Handles dgSoldItems.ItemCommand
    Dim command_Name As String = e.CommandName

    End Sub

    Then you can set a breakpoint in the event to trace if the
    program gets correct button command name. Edit button's
    command name is Edit.

    HTH

    Elton


    >-----Original Message-----
    >I was just following the examples at:
    >
    >http://samples.gotdotnet.com/quickstart/aspplus/doc/webdat

    aaccess.aspx
    >
    >http://samples.gotdotnet.com/quickstart/util/srcview.aspx?

    path=/quickstart/aspplus/samples/webforms/ctrlref/webctrl/d
    atagrid/datagrid4.src
    >
    >Why don't they do the 'handles' thing?
    >
    >Also, why does it all work fine without 'viewstate'

    enabled, as long as I
    >only use DELETE (via BUTTONCOLUMN) or only use

    EDITCOMMANDCOLUMN?
    >
    >Thanks
    >
    >cj
    >
    >
    >
    >"Elton W" <> wrote in

    message
    >news:1b9701c55586$886360c0$...
    >> The event handler should look like
    >>
    >> Private Sub DataGrid1_EditCommand(ByVal source As

    Object,
    >> ByVal e As
    >> System.Web.UI.WebControls.DataGridCommandEventArgs)
    >> Handles dgSoldItems.EditCommand
    >> ' Code
    >>
    >> End Sub
    >>
    >> Your code misses something like
    >>
    >> Handles dgSoldItems.EditCommand
    >>
    >> Without these key works, it's just normal method rather
    >> than event handler.
    >>
    >>
    >> HTH
    >>
    >> Elton Wang

    >
    >
    >.
    >
     
    Elton W, May 11, 2005
    #7
    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. Money
    Replies:
    9
    Views:
    618
    Andre Kostur
    Dec 24, 2006
  2. David C

    Best place to cancel delete

    David C, May 4, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    279
    David C
    May 4, 2007
  3. D. Susman

    Why does "delete" not delete?

    D. Susman, Mar 10, 2008, in forum: C++
    Replies:
    11
    Views:
    546
    Andre Kostur
    Mar 11, 2008
  4. Indu
    Replies:
    9
    Views:
    367
  5. Alex Vinokur
    Replies:
    3
    Views:
    511
    Zoltan Juhasz
    Jun 15, 2012
Loading...

Share This Page