日期:2014-05-17  浏览次数:20547 次

用GridView做一个简单的带提示的删除!
老师让我们做个带提示的删除功能,可是我试了好多参考的方法,都不行,想来请教各位前辈下:
HTML code

<table class="style1">
        <tr>
            <td align="left" height="80">
                当前位置&gt;商品浏览&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:Button ID="Button1" runat="server" Text="查询" />
            </td>
        </tr>
        <tr>
            <td>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                    CellPadding="4" ForeColor="#333333" GridLines="None" 
                    style="position: relative; top: -43px; left: 3px; width: 543px" 
                    AllowPaging="True" DataSourceID="SqlDataSource1" 
                    onrowdeleting="GridView1_RowDeleting" onrowcreated="GridView1_RowCreated">
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <Columns>
                        <asp:BoundField HeaderText="商品编号" DataField="goods_id" />
                        <asp:BoundField HeaderText="商品类别" DataField="category_Name" />
                        <asp:BoundField HeaderText="商品名称" DataField="goods_name" />
                        <asp:BoundField HeaderText="单价" DataField="goods_price" />
                        <asp:TemplateField HeaderText="相关操作">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server">修改</asp:LinkButton>
                                &nbsp;
                                <asp:LinkButton ID="LinkButton2" runat="server" 
                                    CommandArgument='<%# Eval("goods_id") %>' CommandName="delete" 
                                    onclientclick="return confirm('确定要删除吗?')">删除</asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#999999" />
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                </asp:GridView>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:goodsDBConnectionString %>" 
                    
                    
                    SelectCommand=&