激发了未处理的事件“RowDeleting
我的GridView的数据是动态绑定到上面的,在它里面加了一个checkbox,然后单击删除按钮时,删除相应的行(是从数据源删除),前端代码如下: <asp:GridView ID="datausers" runat="server">
<Columns >
<asp:TemplateField >
<ItemTemplate >
<asp:CheckBox ID="cbDel" runat ="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:CheckBox ID="cbAll" runat="server" AutoPostBack="True" Text="全选" />
<br />
<asp:Button ID="Button1" runat="server" Text="删除选中项" />
<asp:Button ID="Button2" runat="server" Text="取消选中项" />
code-behind如下:
Partial Class usermanager
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = False Then
Call binddata()
End If
End Sub
Sub binddata()
datausers.DataSource = Membership.GetAllUsers
datausers.DataBind()
End Sub
Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbAll.CheckedChanged
Dim objItem As GridViewRow
Dim cb As CheckBox
For Each objItem In datausers.Rows
cb = objItem.FindControl("cbDel")
If cbAll.Checked Then
cb.Checked = True
Else
cb.Checked = False
End If
Next
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objitem As GridViewRow
Dim cb As CheckBox
For Each objitem In datausers.Rows
cb = objitem.FindControl("cbDel")
If cb.Checked Then
datausers.DeleteRow(objitem.RowIndex)
End If
Next
Call binddata()
End Sub
End Class
然后出现如题这个问题了!
[[it] 本帖最后由 tm_ma 于 2008-5-10 11:00 编辑 [/it]]