索引超出范围。必须为非负值并小于集合大小。
PartialClassadmin_manageUsersInheritsSystem.Web.UI.PageSubgvDataBind()Me.GridView1.Da...
Partial Class admin_manageUsers
Inherits System.Web.UI.Page
Sub gvDataBind()
Me.GridView1.DataSource = SqlDataSource1
Me.GridView1.DataSource = Membership.GetAllUsers()
Me.GridView1.DataBind()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
gvDataBind()
Me.tbRoles.Visible = False
End If
End Sub
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
Me.GridView1.EditIndex = e.NewEditIndex
gvDataBind()
End Sub
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim IsApproved As Boolean = CType(Me.GridView1.Rows(e.RowIndex).Cells(1).FindControl("chkIsApproved"), CheckBox).Checked
Dim Email As String = CType(Me.GridView1.Rows(e.RowIndex).Cells(2).FindControl("txtEmail"), TextBox).Text
Dim Comment As String = CType(Me.GridView1.Rows(e.RowIndex).Cells(3).FindControl("txtComment"), TextBox).Text
Dim OldUserName As String = Me.GridView1.DataKeys(e.RowIndex).Value(提示超出范围)
Dim CurrentUser As MembershipUser = Membership.GetUser(OldUserName)
CurrentUser.IsApproved = IsApproved
CurrentUser.Email = Email
CurrentUser.Comment = Comment
Membership.UpdateUser(CurrentUser)
Me.GridView1.EditIndex = -1
Me.gvDataBind()
End Sub
Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
Me.GridView1.EditIndex = -1
gvDataBind()
End Sub
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
Dim UserName As String = Me.GridView1.DataKeys(e.RowIndex).Value(提示超出范围)
Membership.DeleteUser(UserName)
Me.GridView1.EditIndex = -1
Me.gvDataBind()
End Sub
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
If e.Row.RowState = DataControlRowState.Normal Or e.Row.RowState = DataControlRowState.Alternate Then
If e.Row.Cells(5).Controls.Count <> 0 Then
Dim btnDelete As LinkButton = e.Row.Cells(5).Controls(0)
If btnDelete IsNot Nothing Then
btnDelete.Attributes("onclick") = "return confirm('你确实要删除这个用户吗?')"
End If
End If
End If
End Sub
这个问题怎么解决啊???哪位大侠站出来帮一下忙,小弟感激不尽啊... 展开
Inherits System.Web.UI.Page
Sub gvDataBind()
Me.GridView1.DataSource = SqlDataSource1
Me.GridView1.DataSource = Membership.GetAllUsers()
Me.GridView1.DataBind()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
gvDataBind()
Me.tbRoles.Visible = False
End If
End Sub
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
Me.GridView1.EditIndex = e.NewEditIndex
gvDataBind()
End Sub
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim IsApproved As Boolean = CType(Me.GridView1.Rows(e.RowIndex).Cells(1).FindControl("chkIsApproved"), CheckBox).Checked
Dim Email As String = CType(Me.GridView1.Rows(e.RowIndex).Cells(2).FindControl("txtEmail"), TextBox).Text
Dim Comment As String = CType(Me.GridView1.Rows(e.RowIndex).Cells(3).FindControl("txtComment"), TextBox).Text
Dim OldUserName As String = Me.GridView1.DataKeys(e.RowIndex).Value(提示超出范围)
Dim CurrentUser As MembershipUser = Membership.GetUser(OldUserName)
CurrentUser.IsApproved = IsApproved
CurrentUser.Email = Email
CurrentUser.Comment = Comment
Membership.UpdateUser(CurrentUser)
Me.GridView1.EditIndex = -1
Me.gvDataBind()
End Sub
Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
Me.GridView1.EditIndex = -1
gvDataBind()
End Sub
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
Dim UserName As String = Me.GridView1.DataKeys(e.RowIndex).Value(提示超出范围)
Membership.DeleteUser(UserName)
Me.GridView1.EditIndex = -1
Me.gvDataBind()
End Sub
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
If e.Row.RowState = DataControlRowState.Normal Or e.Row.RowState = DataControlRowState.Alternate Then
If e.Row.Cells(5).Controls.Count <> 0 Then
Dim btnDelete As LinkButton = e.Row.Cells(5).Controls(0)
If btnDelete IsNot Nothing Then
btnDelete.Attributes("onclick") = "return confirm('你确实要删除这个用户吗?')"
End If
End If
End If
End Sub
这个问题怎么解决啊???哪位大侠站出来帮一下忙,小弟感激不尽啊... 展开
2个回答
2009-12-05
展开全部
多半是没有设置DataKeys,你在GV1的属性栏中找到“数据项”,然后在设置一下表的DataKeys为usesname试试
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询