locked
ObjectDataSource not firing for DeleteMethod RRS feed

  • Question

  • User-2010267424 posted

    Please help.

    I have an ObjectDataSource that is the DataSourceID for the grid on the page. I also have a class that has the Delete Method I want to perform. But when I click on the Delete button within the grid nothing happens. I have followed several tutorials on the web and they all say this should work but it is not. PLEASE HELP!

    Here is my DataSourceObject:

    <asp:ObjectDataSource ID="odsBikersList" runat="server" SelectMethod="FindAll"
            TypeName="BikersDAO" DeleteMethod="DeleteOne"
            OldValuesParameterFormatString="original_{0}" >
            <DeleteParameters>
                <asp:Parameter Name="BikerID" Type="String" />
            </DeleteParameters>
        </asp:ObjectDataSource>

    Here is the code for the method that should fire in my class

     ''' <summary>
        '''
        ''' </summary>
        ''' <param name="BikerID"></param>
        <DataObjectMethod(DataObjectMethodType.[Delete])> _
        Public Function DeleteOne(ByVal BikerID As String) As IEnumerable(Of Bikers)
            Return (From c In Me.Bikerss Where c.BikerID = BikerID Select c).ToList()
        End Function

    And here is the code for the grid:

    <asp:GridView ID="gvBikers" runat="server" DataSourceID="odsBikersList" AutoGenerateDeleteButton="true"
                    CssClass="datagrid" GridLines="None" AutoGenerateColumns="False"
                     OnSelectedIndexChanged="GVBikers_SelectedIndexChanged" DataKeyNames="BikerID">
                    <Columns>
                        <asp:BoundField DataField="BikerID" HeaderText="BikerID" ReadOnly="false"
                            SortExpression="BikerID" />
                        <asp:BoundField DataField="F_Name" HeaderText="F_Name" ReadOnly="false"
                            SortExpression="F_Name" />
                        <asp:BoundField DataField="M_Name" HeaderText="M_Name" ReadOnly="false"
                            SortExpression="M_Name" />
                        <asp:BoundField DataField="L_Name" HeaderText="L_Name" ReadOnly="false"
                            SortExpression="L_Name" />
                        <asp:BoundField DataField="MyID" HeaderText="MyID" ReadOnly="false"
                            SortExpression="MyID" />
                        <asp:BoundField DataField="Site" HeaderText="Site" ReadOnly="false"
                            SortExpression="Site" />
                        <asp:BoundField DataField="bk_Building" HeaderText="bk_Building"
                            ReadOnly="false" SortExpression="bk_Building" />
                        <asp:BoundField DataField="bk_City" HeaderText="bk_City" ReadOnly="false"
                            SortExpression="bk_City" />
                        <asp:BoundField DataField="bk_Zip" HeaderText="bk_Zip" ReadOnly="false"
                            SortExpression="bk_Zip" />
                        <asp:BoundField DataField="bk_Phone" HeaderText="bk_Phone" ReadOnly="false"
                            SortExpression="bk_Phone" />
                        <asp:BoundField DataField="email" HeaderText="email" ReadOnly="false"
                            SortExpression="email" />
                        <asp:BoundField DataField="DeptZone" HeaderText="DeptZone" ReadOnly="false"
                            SortExpression="DeptZone" />
                        <asp:BoundField DataField="QuartID" HeaderText="QuartID" ReadOnly="false"
                            SortExpression="QuartID" />
                        <asp:BoundField DataField="BikerDays" HeaderText="BikerDays" ReadOnly="false"
                            SortExpression="BikerDays" />
                        <asp:BoundField DataField="BikerMiles" HeaderText="BikerMiles" ReadOnly="false"
                            SortExpression="BikerMiles" />
                        <asp:BoundField DataField="BikerTime" HeaderText="BikerTime" ReadOnly="false"
                            SortExpression="BikerTime" />
                        <asp:BoundField DataField="BKLockID" HeaderText="BKLockID" ReadOnly="false"
                            SortExpression="BKLockID" />
                        <asp:BoundField DataField="bk_Start_DT" HeaderText="bk_Start_DT"
                            ReadOnly="false" SortExpression="bk_Start_DT" />
                        <asp:BoundField DataField="bk_End_DT" HeaderText="bk_End_DT" ReadOnly="false"
                            SortExpression="bk_End_DT" />
                        <asp:BoundField DataField="bk_Quarter" HeaderText="bk_Quarter" ReadOnly="false"
                            SortExpression="bk_Quarter" />
                        <asp:BoundField DataField="bk_Year" HeaderText="bk_Year" ReadOnly="false"
                            SortExpression="bk_Year" />
                        <asp:BoundField DataField="bk_Comments" HeaderText="bk_Comments"
                            ReadOnly="false" SortExpression="bk_Comments" />
                        <asp:BoundField DataField="IsActive" HeaderText="IsActive" ReadOnly="false"
                            SortExpression="IsActive" />
                            <asp:TemplateField>
                             <ItemTemplate>
                                <asp:LinkButton ID="btnViewDetails" runat="server" Text="Edit" CommandName="Select" />
                             </ItemTemplate>
                         </asp:TemplateField>
                    </Columns>
                </asp:GridView>

     

     

     

     

     

     

    Thank you for the help.

    Tuesday, March 29, 2011 11:24 AM

All replies

  • User-851968219 posted
    Public Class BikersDAO
        '<asp:ObjectDataSource ID="odsBikersList" runat="server" SelectMethod="FindAll" 
        '    TypeName="BikersDAO" DeleteMethod="DeleteOne" 
        '    OldValuesParameterFormatString="original_{0}" >
        '    <DeleteParameters>
        '        <asp:Parameter Name="BikerID" Type="String" />
        '    </DeleteParameters>
        '</asp:ObjectDataSource>
    
        Public Function FindAll() As IEnumerable(Of Bikers)
            Dim abc As New List(Of Bikers)
            abc.Add(New Bikers("1", "one"))
            abc.Add(New Bikers("2", "two"))
            abc.Add(New Bikers("3", "three"))
            Return abc
        End Function
    
        Public Function DeleteOne(ByVal BikerID As String) As IEnumerable(Of Bikers)
            ' check to see if I can hit it
            Return New List(Of Bikers)
        End Function
    
    
    End Class
    
    
    Public Class Bikers
    
        Public Sub New(ByVal pBikerId As String, ByVal pName As String)
            _BikerID = pBikerId
            _Name = pName
        End Sub
    
        Private _BikerID As String
        Public Property BikerID() As String
            Get
                Return _BikerID
            End Get
            Set(ByVal value As String)
                _BikerID = value
            End Set
        End Property
    
        Private _Name As String
        Public Property Name() As String
            Get
                Return _Name
            End Get
            Set(ByVal value As String)
                _Name = value
            End Set
        End Property
    
    End Class
    
    
    <asp:gridview autogeneratecolumns="False" datasourceid="ObjectDataSource1" runat="server" id="GridView1"> <columns></columns><columns></columns><columns></columns><columns></columns><columns></columns><columns></columns><columns></columns><columns></columns> <asp:boundfield datafield="BikerID" headertext="BikerID" sortexpression="BikerID"></asp:boundfield> <asp:boundfield datafield="Name" headertext="Name" sortexpression="Name"></asp:boundfield> <columns></columns><columns></columns><columns></columns><columns></columns><columns></columns><columns></columns><columns></columns><columns></columns> </asp:gridview> <asp:objectdatasource deletemethod="DeleteOne" selectmethod="FindAll" typename="WebApplication1.BikersDAO" runat="server" id="ObjectDataSource1"> <deleteparameters></deleteparameters><deleteparameters></deleteparameters><deleteparameters></deleteparameters><deleteparameters></deleteparameters><deleteparameters></deleteparameters><deleteparameters></deleteparameters><deleteparameters></deleteparameters><deleteparameters></deleteparameters> <asp:parameter name="BikerID" type="String"></asp:parameter> <deleteparameters></deleteparameters><deleteparameters></deleteparameters><deleteparameters></deleteparameters><deleteparameters></deleteparameters><deleteparameters></deleteparameters><deleteparameters></deleteparameters><deleteparameters></deleteparameters><deleteparameters></deleteparameters> </asp:objectdatasource>

     

    <

    asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

     

    DataSourceID="ObjectDataSource1">

      <Columns> <asp:BoundField DataField="BikerID" HeaderText="BikerID" SortExpression="BikerID" />  <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />  </Columns> </asp:GridView> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="DeleteOne" SelectMethod="FindAll" TypeName="WebApplication1.BikersDAO"> <DeleteParameters> <asp:Parameter Name="BikerID" Type="String" /> </DeleteParameters> </asp:ObjectDataSource> 

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    See If it helps, when i did this I was able to call delete successfully

    Thursday, April 28, 2011 3:51 PM