Rene

Rene

  • NA
  • 16
  • 23.7k

Gridview - Delete and Edit button not working

Dec 5 2010 10:57 PM
I have a gridview with an object data source. I have the edit and delete button on each row but cannot get either one of them to work. I do not receive an error, it just doesn't delete. Refreshing does not show deleted either.
The method within the dataset is

 DELETE FROM Book
WHERE        (BookID = @Original_BookID)
 UPDATE       
Book
SET                ISBN = @ISBN, Title = @Title, Author = @Author, Status = @Status, Loaned = @Loaned, Series = @Series, Description = @Description
WHERE        (BookID = @Original_BookID)

I have a business layer that defines the methods for update and delete:

 

[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
public bool DeleteBook(int
bookid)
{
// Delete book record

int
rowsAffected = Adapter.Delete(bookid);
// return true if one row deleted

return
rowsAffected == 1;
}

public bool UpdateBook(int bookid, string isbn, string title, string author, string status, string loaned,
string series, string
description)
{
BookDataSet.BookDataTable
books = Adapter.GetBookByBookID(bookid);
if
(books.Count == 0)
return false; // no matching record found, return false

else

{
BookDataSet.BookRow
book = books[0];
book.ISBN = isbn;
book.Title = title;
book.Author = author;
book.Status = status;
if (loaned == null
) book.SetLoanedNull();
else
book.Loaned = loaned;
if (series == null
) book.SetSeriesNull();
else
book.Series = series;
if (description == null
) book.SetDescriptionNull();
else
book.Description = description;
// Update book record

int
rowsAffected = Adapter.Update(book);
// Return true if one row updated

return
rowsAffected == 1;
}

 
aspx:
 

<asp:ObjectDataSource ID="odsBooks" runat="server" SelectMethod="GetBooks" InsertMethod="AddBook"
TypeName="BookManager" DeleteMethod="DeleteBook" UpdateMethod="UpdateBook">

<UpdateParameters>

<asp:Parameter Name="isbn" Type="String" />

<asp:Parameter Name="title" Type="String" />

<asp:Parameter Name="author" Type="String" />

<asp:Parameter Name="status" Type="String" />

<asp:Parameter Name="loaned" Type="String" />

<asp:Parameter Name="series" Type="String" />

<asp:Parameter Name="description" Type="String" />

</UpdateParameters>

<
DeleteParameters>

<asp:Parameter Name="bookid" Type="Int32" />

</DeleteParameters>

</
asp:ObjectDataSource>

<
div style="overflow:auto; height:286px; width: 1097px;">
<asp:GridView ID="gvBooks" runat="server" DataKeyNames="BookID" AllowSorting="True"

AutoGenerateColumns="False" BackColor="#CC00FF" BorderColor="#FF0066" ForeColor="#FFCCFF"

BorderStyle="Double" BorderWidth="5px" CssClass="DataWebContolStyle" Font-Size="Small"

Font-Names="Kristen ITC" OnSelectedIndexChanged="gvBooks_SelectedIndexChanged"

OnRowDeleting="gvBooks_RowDeleting" OnRowEditing="gvBooks_RowEditing"

OnRowCancelingEdit="gvBooks_RowCancelingEdit" OnRowUpdating="gvBooks_RowUpdating" >

<
Columns>

<asp:BoundField DataField="BookID" HeaderText="BookID" ReadOnly="True"

InsertVisible="False" SortExpression="BookID" />

<asp:BoundField DataField="ISBN" HeaderText="ISBN" SortExpression="ISBN" />

<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />

<asp:BoundField DataField="Author" HeaderText="Author" SortExpression="Author" />

<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />

<asp:BoundField DataField="Loaned" HeaderText="Loaned" SortExpression="Loaned" />

<asp:BoundField DataField="Series" HeaderText="Series" SortExpression="Series" />

<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />

<asp:CommandField ShowEditButton="True" ItemStyle-BorderStyle="Double"

ItemStyle-BorderColor="#FF33CC" ItemStyle-BackColor="#FF33CC" />

<asp:TemplateField ShowHeader="False">

<ItemTemplate>

<asp:LinkButton ID="btnDelete" runat="server" CausesValidation="False"

CommandName="Delete" Text="Delete"

OnClientClick="return confirm('Are you sure you want to delete this book?');"

Font-Size="Small" ForeColor="#FFCCFF" Font-Bold="True" BackColor="#FF33CC"

BorderColor="#FF33CC" BorderStyle="Double" BorderWidth="3">

</asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

</Columns>

<
EditRowStyle BackColor="#FFCCFF" BorderColor="#FF0066" Font-Names="Kristen ITC"

ForeColor="#CC0099" />

<SelectedRowStyle BackColor="#FFCCFF" BorderColor="#FF0066" Font-Names="Kristen ITC"

ForeColor="#CC0099" />

</asp:GridView>

I have had this working with the sqldatasource but cannot seem to get it working with ods.
Any help would be really appreciated!!  Thanks!!!

 

Answers (10)