无法运行gridview.databind(),eventargs错误

时间:2012-10-11 14:34:51

标签: asp.net

我有一个列表框,在选定的更改中,运行一个方法将数据绑定到gridview。我收到错误:无法将'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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

我忘了我问了这个问题,但是删除RowDatabound并重新创建它修复了它。我知道这很奇怪。