Welcome to 陈俊峰's ---BeetleHeaded Man Blog !

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  58 随笔 :: 32 文章 :: 18 评论 :: 0 Trackbacks

Part 1 :Qusetion Details:(that's not really i wrote,i just quote a same sample as my encountered) 

 
have a gridview and the GridView_RowEditing event is firing twice when I click the edit button and the GridView_RowDeleting event is firing twice on a single delete.  I don't think there's anything that I'm doing in my code that would cause this, but I'm including the code for the two events.  Has anyone encountered this problem?

Here's the code for RowEditing:
<code>
Protected Sub gv_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gv.RowEditing
        gv.Columns(columnIndex.Delete).Visible = True
        gv.Columns(columnIndex.Id).Visible = False
        gv.EditIndex = e.NewEditIndex
    End Sub
</code>

And here's the code for RowDeleting:
<code>
Protected Sub gv_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gv.RowDeleting
        e.Cancel = True
        Dim lblFName As Label
        lblFName= CType(gv.Rows(gv.EditIndex).FindControl("lblFName"), Label)
        Dim lblLName As Label
        lblLName= CType(gv.Rows(gv.EditIndex).FindControl("lblLName"), Label)

        myObject.myClass.DeleteTemp(CType(lblBookletNum.Text, Integer), lblCare.Text)
        gvTempVisits.EditIndex = -1
    End Sub
</code>

Part 2 : A Reply From Someone

verify if in the declarative code of your GridView control are set the OnRowDeleting and OnRowEditing attributes. If so, remove either this attributes or the Handles clauses of your handler events.

I mean if your gridview is declared as follows:

[...]
   <asp:GridView id="gv" runat="Server" OnRowDeleting="gv_RowDeleting" OnRowEditing="gv_RowEditing"
>
      [...]
   </asp:GridView>
[...]

And in your methods to handle the events are as follows:

[...]
   Protected Sub gv_RowDeleting(............)
Handles gv.RowDeleting
      [...]
   End Sub
[...]

This events will be called twice.


Part 3: A Great Discussion about it  i found !

http://www.issociate.de/board/post/285047/help_please_on_GridView_commands_+_AutoEventWireUp

posted on 2006-04-12 13:20 Jeff-Chen 阅读(552) 评论(0)  编辑 收藏 引用 所属分类: .NET

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理