?
Solved

DataGrid Delete Command

Posted on 2009-02-18
7
Medium Priority
?
410 Views
Last Modified: 2012-05-06
I found this code on completing a datagrid delete command but it does not seem to work for me and don't understand why at this point.  The following is mydatagrid and then the code behind.

<asp:datagrid id="myDataGrid" runat="server" BorderWidth="1px" CellPadding="6" BorderColor="#404040" Font-Size="12px" Font-Names="Verdana,Arial,sans-serif" AutoGenerateColumns="False" HeaderStyle-HorizontalAlign="Center"
ItemStyle-HorizontalAlign="Center" au>
<AlternatingItemStyle BackColor="LightSteelBlue"></AlternatingItemStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White" BackColor="SteelBlue"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="intSurveyID" HeaderText="SurveyID"></asp:BoundColumn>
<asp:BoundColumn DataField="strFullName" HeaderText="Full Name"></asp:BoundColumn>
<asp:BoundColumn DataField="strGrade" HeaderText="Rank/GS-Level"></asp:BoundColumn>
<asp:BoundColumn DataField="strDate" HeaderText="Date of Survey" DataFormatString="{0:yyyy/MM/dd}">
<HeaderStyle Wrap="False"></HeaderStyle>
</asp:BoundColumn>
<asp:ButtonColumn Text="Delete" HeaderText="Delete" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:datagrid>
Private Sub myDataGrid_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
        Dim surveyId As String = e.Item.Cells(0).Text
      
        sql = "Delete from tblFTSurvey where intSurveyId = " & surveyId
        insertUpdateDelete(sql)
        '' Binds the grid so that change can be seen 
        myDataGrid.DataSource = myDataTable
        myDataGrid.DataBind()
 
    End Sub

Open in new window

0
Comment
Question by:kdeutsch
  • 3
  • 3
7 Comments
 
LVL 16

Expert Comment

by:burakiewicz
ID: 23672918
are you ever reloading or removing the record from  myDataTable after you delete it
0
 
LVL 27

Expert Comment

by:nmarun
ID: 23673107
What burakiewicz is saying is that you need to repopulate the 'myDataTable' after the insertupdateDelete method.
0
 

Author Comment

by:kdeutsch
ID: 23673810
Yes,
I actually had the wrong bind in there so I put in the correct one and it still does not delete any information from the database.  When I click it looks like it posts and then posts back with same information.  When i go into SQL the record is still there.

  Private Sub myDataGrid_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
        Dim surveyId As String = e.Item.Cells(0).Text
     
        sql = "Delete from tblFTSurvey where intSurveyId = " & surveyId
       
        insertUpdateDelete(sql)
        '' Binds the grid so that change can be seen
        OrderDataGrid()
    End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:burakiewicz
ID: 23673987
what is in this method insertUpdateDelete(sql)? also is surveyId
 showing the correct value
0
 

Author Comment

by:kdeutsch
ID: 23674018
Hi,
The method insertupdatedelete is a call to the Db connectiona to take the SQL string and perform that command.  WHen I do a response. write I can't even get into it.  When i click on the link it posts and refreshes without doing the response.write
0
 
LVL 16

Accepted Solution

by:
burakiewicz earned 1000 total points
ID: 23674131
this might help
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system.web/html/3453f84f-7041-b92e-f859-85fffdc60fbb.htm
add this to your datagrid
OnItemCommand="myDataGrid_Command"
and under columns change your delete to this
<asp:ButtonColumn
                 HeaderText="Delete item"
                 ButtonType="LinkButton"
                 Text="Delete"
                 CommandName="Delete"/>
then add this code

Sub myDataGrid_Command(sender As Object, e As DataGridCommandEventArgs)
 
         Select (CType(e.CommandSource, LinkButton)).CommandName
 
            Case "Delete"
               DeleteItem(e)
 
            ' Add other cases here, if there are multiple ButtonColumns in 
            ' the DataGrid control.
 
            Case Else
               ' Do nothing.
 
         End Select
 
      End Sub
 
      Sub DeleteItem(e As DataGridCommandEventArgs)
 Dim surveyId As String = e.Item.Cells(0).Text
     
        sql = "Delete from tblFTSurvey where intSurveyId = " & surveyId
       
        insertUpdateDelete(sql)
        '' Binds the grid so that change can be seen 
        OrderDataGrid()
 
      End Sub

Open in new window

0
 

Author Closing Comment

by:kdeutsch
ID: 31548369
Sorry took so long to award points
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question