0
 protected void gvRequest_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                bm.DeleteBookRequest(Convert.ToInt32(e.CommandArgument));
                GetBooks();
            GetRequest();
            }
        }

    <asp:GridView ID="gvBooks" runat="server" AutoGenerateColumns="false" DataKeyNames="Id"
            BorderStyle="None" OnRowCommand="gvBooks_RowCommand" CssClass="gvBooks" CellPadding="5"
            CellSpacing="7" ForeColor="Blue" OnRowDeleting="gvBooks_RowDeleting">
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" />
                <asp:BoundField DataField="Title" HeaderText="Title" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton CommandName="Select" CommandArgument='<%# Eval("Title") %>' runat="server"
                            ID="lb_Id">Select</asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton CommandName="Delete" CommandArgument='<%# Eval("Title") %>' runat="server"
                            ID="lb_Title">Delete</asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:GridView ID="gvReviews" runat="server" AutoGenerateColumns="false" OnRowCommand="gvReviews_RowCommand"
            OnRowDeleting="gvReviews_RowDeleting" CellPadding="5" CellSpacing="7" ForeColor="Blue">
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" />
                <asp:BoundField DataField="Subject" HeaderText="Subject" />
                <asp:BoundField DataField="Username" HeaderText="Username" />
                <asp:BoundField DataField="Review" HeaderText="Review" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton CommandName="Delete" CommandArgument='<%# Eval("Id") %>' runat="server"
                            ID="lb_IdDel">Delete</asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:GridView ID="gvRequest" runat="server" onrowcommand="gvRequest_RowCommand" AutoGenerateColumns="false">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                    <asp:Label ID="lblName" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                    <asp:Label ID="lblUsername" runat="server" Text='<%# Eval("Username") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                    <asp:LinkButton ID="lbDelete" CommandName="Delete" CommandArgument='<%# Eval("id") %>' runat="server" Text="Delete"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

当我单击删除链接按钮时,输出是一个空白页。

点击按钮点击后的视图源如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<SCRIPT type=text/javascript src="http://www.google-analytics.com/ga.js" 
async="true"></SCRIPT>

<SCRIPT type=text/javascript src="http://sg.perion.com/v1.1/js/gt.js" 
async="true" onload="null"></SCRIPT>
</HEAD>
<BODY></BODY></HTML>

internal void DeleteBookRequest(int id)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "Delete from bookrequest where id=@id";
            cmd.Parameters.Add("@id", SqlDbType.BigInt, 19, "id").Value = id;
            cmd.Connection = connection;
            connection.Open();
            cmd.ExecuteNonQuery();
            connection.Close();            
        }
4

0 回答 0