I've got a vexing problem with an ObjectDataSource (bound to a DetailsView) that is not checking the DeleteParameters for a delete method (which I specified both in the markup and the data object as requiring an integer). Here's the markup:

<asp:ObjectDataSource ID="odsFrontPageBannerDetails" runat="server" DataObjectTypeName="FrontPage.Banner" DeleteMethod="DeleteFrontPageBanner" InsertMethod="InsertFrontPageBanner" SelectMethod="GetFrontPageBanner" UpdateMethod="UpdateFrontPageBanner" TypeName="FrontPage.BannersData">
    <DeleteParameters>
        <asp:Parameter Name="idx" Type="Int32"  />
    </DeleteParameters>
    <SelectParameters>
        <asp:ControlParameter ControlID="GridView1" Name="idx" PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
</asp:ObjectDataSource>

and the object:

<DataObjectMethod(DataObjectMethodType.Delete, True)> _
Public Shared Function DeleteFrontPageBanner(ByVal idx As Integer) As Integer
    Dim retval As Integer = 0
    Dim iReturnCode As Integer = 0
    Using conn As New SqlConnection(GetConnStr())
        Using cmd As New SqlCommand
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "FrontPage_BannerDelete"
            cmd.Connection = conn
            cmd.Parameters.AddWithValue("@idx", idx)
            Try
                conn.Open()
                iReturnCode = cmd.ExecuteNonQuery
                If iReturnCode >= 0 Then
                    retval = 1
                    LastErrorMsg = String.Empty
                Else
                    Throw New DataException("Return code is: " & iReturnCode)
                End If
            Catch ex As Exception
                LastErrorMsg = ex.Message
                retval = 0
            End Try
        End Using
    End Using
    Return retval
End Function

and the detailsview markup:

   <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" CellPadding="4" DataSourceID="odsFrontPageBannerDetails" ForeColor="#333333" GridLines="None" Height="50px" Width="338px">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
        <EditRowStyle BackColor="#999999" />
        <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
        <Fields>
            <asp:BoundField DataField="idx" HeaderText="idx" ReadOnly="True" SortExpression="idx" />
            <asp:CheckBoxField DataField="Active" HeaderText="Active" SortExpression="Active" />
            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
            <asp:BoundField DataField="BannerText" HeaderText="BannerText" SortExpression="BannerText" />
            <asp:BoundField DataField="BannerImage" HeaderText="Banner Image" SortExpression="BannerImage" />
            <asp:BoundField DataField="BannerLink" HeaderText="Go To Page Link" SortExpression="BannerLink" />
            <asp:BoundField DataField="BackgroundColor" HeaderText="Background Color" SortExpression="BackgroundColor" />
            <asp:BoundField DataField="BannerHeight" HeaderText="Banner Height" HtmlEncode="False" SortExpression="BannerHeight" />
            <asp:BoundField DataField="StartDate" DataFormatString="{0:MM/dd/yyyy}" HeaderText="Start Date" HtmlEncode="False" SortExpression="StartDate" />
            <asp:BoundField DataField="EndDate" DataFormatString="{0:MM/dd/yyyy}" HeaderText="End Date" HtmlEncode="False" SortExpression="EndDate" />
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
        </Fields>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    </asp:DetailsView>

The error indicates that the DeleteParameters are completely ignored! (I followed an example straight from a video tutorial and it worked fine for the author)

ObjectDataSource 'odsFrontPageBannerDetails' could not find a non-generic method 'DeleteFrontPageBanner' that takes parameters of type 'FrontPage.Banner'.

Any ideas? I've tried rebuilding the solution and the page with no luck!

After trying every combination of parameters I could think of with no success, I decided to just change the delete method to accept the Frontpage.Banner object and now it deletes without an error - See change below:

<DataObjectMethod(DataObjectMethodType.Delete, True)> _
Public Shared Function DeleteFrontPageBanner(ByVal o As FrontPage.Banner) As Integer
    Dim retval As Integer = 0
    Dim iReturnCode As Integer = 0
    Using conn As New SqlConnection(GetConnStr())
        Using cmd As New SqlCommand
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "FrontPage_BannerDelete"
            cmd.Connection = conn
            cmd.Parameters.AddWithValue("@idx", o.idx)
            Try
                conn.Open()
                iReturnCode = cmd.ExecuteNonQuery
                If iReturnCode >= 0 Then
                    retval = 1
                    LastErrorMsg = String.Empty
                Else
                    Throw New DataException("Return code is: " & iReturnCode)
                End If
            Catch ex As Exception
                LastErrorMsg = ex.Message
                retval = 0
            End Try
        End Using
    End Using
    Return retval
End Function

Still would love an explanation of why the delete parameters in the markup are completely ignored.

Related posts

Recent Viewed