我在asp.net.i中使用了Gridview_PageIndexChanging事件,使用了这样的代码:
gridFileDetails.PageIndex = e.NewPageIndex
在单击下一页的运行时间内,它会生成错误:
在RowCommand事件中类型的例外 发生'System.InvalidCastException' 在FFK.DLL中但未在用户中处理 代码
其他信息:无法投射 对象类型 'System.Web.UI.WebControls.ContentPlaceHolder' 输入 'System.Web.UI.WebControls.GridViewRow'。
,
我使用了以下RowCommand事件:
Protected Sub gridFileDetails_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gridFileDetails.RowCommand
Dim row As GridViewRow = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow)
Dim rowkey As DataKey = Me.gridFileDetails.DataKeys(row.DataItemIndex)
Dim key As String = rowkey(0).ToString()
If e.CommandName = "FileStatus" And e.CommandArgument <= 0 Then
Response.Redirect("FFKFile.aspx?FileId=" + key)
ElseIf e.CommandName = "TradexStatus" And e.CommandArgument <= 0 Then
Response.Redirect("TradeX.aspx?FileId=" + key)
ElseIf e.CommandName = "BondStatus" And e.CommandArgument <= 0 Then
Response.Redirect("BondMaster.aspx?FileId=" + key)
ElseIf e.CommandName = "FDStatus" And e.CommandArgument <= 0 Then
Response.Redirect("FrmFileDocument.aspx?FileId=" + key)
ElseIf e.CommandName = "InvoiceStatus" And e.CommandArgument <= 0 Then
Response.Redirect("InvoiceMaster.aspx?FileId=" + key)
ElseIf e.CommandName = "PDStatus" And e.CommandArgument <= 0 Then
Response.Redirect("PackagingDetails.aspx?FileId=" + key)
End If
End Sub
你可以解决这个问题吗?
我在RowCommand事件的第一行收到错误,即。,
Dim row As GridViewRow = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow)
在PageIndexChanging事件中,我写了如下:
受保护的子gridFileDetails_PageIndexChanging(ByVal sender As Object,ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)处理gridFileDetails.PageIndexChanging gridFileDetails.PageIndex = e.NewPageIndex 结束子
答案 0 :(得分:1)
而不是:
Dim row As GridViewRow = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow)
使用EventArgs
中的索引以编程方式抓取行:
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = gridFileDetails.Rows(index)
答案 1 :(得分:1)
引用System.Web.UI.WebControls.GridViewCommandEventArgs类的MSDN,提取gridviewrow的示例如下:
' Convert the row index stored in the CommandArgument
' property to an Integer.
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
' Retrieve the row that contains the button clicked
' by the user from the Rows collection.
Dim row As GridViewRow = ContactsGridView.Rows(index)
看看这是否有助于你获得没有施法错误的行。
答案 2 :(得分:1)
这可能会有所帮助:
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = gridFileDetails.Rows(index)