Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Cancel does Delete instead!??

Reply
Thread Tools

Cancel does Delete instead!??

 
 
cj
Guest
Posts: n/a
 
      05-10-2005
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



 
Reply With Quote
 
 
 
 
cj
Guest
Posts: n/a
 
      05-10-2005
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
>
>
>



 
Reply With Quote
 
 
 
 
Elton W
Guest
Posts: n/a
 
      05-10-2005
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
>>
>>
>>

>
>
>.
>

 
Reply With Quote
 
cj
Guest
Posts: n/a
 
      05-10-2005
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
>>>
>>>
>>>

>>
>>
>>.
>>



 
Reply With Quote
 
Elton W
Guest
Posts: n/a
 
      05-10-2005
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
>>>>
>>>>
>>>>
>>>
>>>
>>>.
>>>

>
>
>.
>

 
Reply With Quote
 
cj
Guest
Posts: n/a
 
      05-10-2005
I was just following the examples at:

http://samples.gotdotnet.com/quickst...ataaccess.aspx

http://samples.gotdotnet.com/quickst.../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



 
Reply With Quote
 
Elton W
Guest
Posts: n/a
 
      05-11-2005
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/quickst...lus/doc/webdat

aaccess.aspx
>
>http://samples.gotdotnet.com/quickst.../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

>
>
>.
>

 
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
Delete does not really delete Hong Chen C++ 2 06-16-2008 08:49 PM
Why does "delete" not delete? D. Susman C++ 11 03-11-2008 10:03 PM
Best place to cancel delete David C ASP .Net 0 05-04-2007 07:53 PM
HELP CANCEL CANCEL CANCEL Carmen Rosario Computer Support 7 04-06-2005 11:04 PM
confirm does not cancel postback? JerryK ASP .Net 2 03-22-2005 04:46 PM



Advertisments