当前位置:编程学习 > C#/ASP.NET >>

C# net2.0 中的web控件gridview 的事件RowDataBound据然在事件RowDeleting之后执行,这是为什么啊!

我的代码如下:
页面:
<td>
                <asp:GridView ID="GV_Product" runat="server" AutoGenerateColumns="False" Width="100%"
                    AllowPaging="True" OnRowDataBound="GV_Product_RowDataBound" OnRowDeleting="GV_Product_RowDeleting">
                    <Columns>
                        <asp:BoundField DataField="id" HeaderText="id">
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                        </asp:BoundField>
                        <asp:BoundField DataField="ProductName" HeaderText="产品名称">
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                        </asp:BoundField>
                        <asp:BoundField DataField="ProductPrice" HeaderText="产品价格">
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                        </asp:BoundField>
                        <asp:BoundField DataField="PriceDays" HeaderText="使用天数">
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                        </asp:BoundField>
                        <asp:BoundField DataField="Detail" HeaderText="详细说明">
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                        </asp:BoundField>
                        <asp:ButtonField ButtonType="Button" CommandName="EDIT" Text="编辑">
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                        </asp:ButtonField>
                        <asp:ButtonField ButtonType="Button" CommandName="DELETE" Text="删除">
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                        </asp:ButtonField>
                    </Columns>
                    <HeaderStyle BackColor="Maroon" ForeColor="White" Height="30px" />
                    <AlternatingRowStyle BackColor="#E0E0E0" HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:GridView>
            </td>

后台:
    protected void GV_Product_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[6].Attributes.Add("onclick", "javascript:return confirm('您确定要这样操作吗?')");
        }
    }
    protected void GV_Product_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Clear();
        //得到所选类型的ID值
        string _id = this.GV_Product.Rows[e.RowIndex].Cells[0].Text;
        Product _product = Product.Instance();
        if (_product.DELETE_ProductByID(int.Parse(_id)))
        {
            this.LB_Message.Text = "删除记录成功!";
        }
        else
        {
            this.LB_Message.Text = "记录被引用,删除记录失败!";
        }
        Tab_EDIT.Visible = false;
        GView_ListBind();
    }

现在的情况是事件GV_Product_RowDataBound后于事件GV_Product_RowDeleting发生,真是奇怪,
有人遇过这个问题吗? --------------------编程问答-------------------- 为什么,事件的执行总要有顺序吧

这是规定,rowdatabond是数据绑定,rowdeleting是数据删除,删除之后肯定要绑定的啊,要不还显示原来的吗

好像这两个也没有顺序之分,数据绑定是第一次或者以后对数据有操作之后,就要进行的 --------------------编程问答-------------------- to:virusplayer 
你好像没有明白我的意思,我是想问:在删除之前有一个“是否确认”的提示,而这样写,这个提示跑到了删除事件后面去了,这样这个提示就没有用了
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,