2

我有一个列表框,它在选定的更改上运行一种将数据绑定到网格视图的方法。我收到错误消息:无法将 'System.EventArgs' 类型的对象转换为 'System.Web.UI.WebControls.GridViewRowEventArgs'。我的代码的其他部分从其他控件调用另一个 gridview.databind(),所以我不知道为什么它现在抛出这个错误?

Protected Sub lstEmployees_SelectedIndexChanged(ByVal sender As Object, ByVal e As     EventArgs) Handles lstEmployees.SelectedIndexChanged
    Dim x As Int16
    Dim startStr, endStr As String

    If txtAdminSelectedDate.Text <> "" Then
        dtWeeks = GetWeek(txtAdminSelectedDate.Text)
    End If

    If dtWeeks.Rows.Count > 0 Then
        x = dtWeeks.Rows(0).Item(0).ToString().IndexOf("-")
        endStr = dtWeeks.Rows(0).Item(0).ToString().Substring(x + 1, 11)
        startStr = dtWeeks.Rows(0).Item(1).ToString()
        dtWrkHours = GetHoursOfTheWeek(startStr, endStr, _user).Tables(0)
        gvAdmin.DataSource = dtWrkHours
        gvAdmin.DataBind()
        sStatus = String.Empty
        aStatus = String.Empty
        AdminTot = 0
        timeTot = 0
    End If

End Sub
4

2 回答 2

1

我忘了我问过这个问题,但是删除 RowDatabound 并重新创建它可以解决它。我知道这很奇怪。

于 2013-02-06T16:08:47.483 回答
0

您的网格可能有一个错误的方法签名。确保它看起来像这样:

注意:特别注意参数:ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs

Public Sub xyz_DataBind(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles xyz.RowDataBound
   ...
End Sub
于 2012-10-11T14:42:19.487 回答