本文介绍了有什么不对的ASP.NET code ....? (数据网格+的ImageButton)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
    If e.CommandName = "Hold" Then
        Dim gvRow As GridViewRow = CType(CType(sender, Control).Parent.Parent, GridViewRow)
        Dim index As Integer = gvRow.RowIndex
        Dim myRow As GridViewRow = GridView1.Rows(index)
        'Find the checkbox
        Dim lab5 As Label = DirectCast(myRow.FindControl("Label5"), Label)
        Dim label2 As Label = DirectCast(myRow.FindControl("Label2"), Label)
        Dim label4 As Label = DirectCast(myRow.FindControl("Label4"), Label)
        Dim label22 As Label = DirectCast(myRow.FindControl("Label22"), Label)
        Me.Response.Redirect("Select_seats.aspx?s_no=" & label22.Text.ToString & "&" & "journey=" & Label6.Text & "&" & "seater=" & label4.Text & "&" & "sleeper=" & label2.Text & "&" & "service=" & lab5.Text.ToString)
    End If
End Sub

这code给错误:

在此行

IM gvRow作为GridViewRow = CTYPE(CTYPE(发件人,控制).Parent.Parent,GridViewRow)

im gvRow As GridViewRow = CType(CType(sender, Control).Parent.Parent, GridViewRow)

错误:

无法转换类型'ASP.vendors_select_service_aspx对象键入'System.Web.UI.WebControls.GridViewRow。

Unable to cast object of type 'ASP.vendors_select_service_aspx' to type 'System.Web.UI.WebControls.GridViewRow'.

推荐答案

为什么你遍历网格中所有行?因此要重定向的第一行,而不是导致该保留命令的行。在任何控制的 GridViewRow是GridViewRow本身,这就是需要获得关于你的标签。

Why do you iterate all rows in Grid? Therefore you are redirecting on the first row and not on the row that causes the "Hold-Command". The NamingContainer of any control in the GridViewRow is the GridViewRow itself and this is what FindControl needs to get the reference to your labels.

    If e.CommandName = "Hold" Then
        Dim row As GridViewRow = DirectCast(DirectCast(e.CommandSource, Control).NamingContainer, GridViewRow)
        Dim lab5 As Label = DirectCast(row.FindControl("Label5"), Label)
        Dim label2 As Label = DirectCast(row.FindControl("Label2"), Label)
        Dim label4 As Label = DirectCast(row.FindControl("Label4"), Label)
        Dim label6 As Label = DirectCast(row.FindControl("label6"), Label)
        Dim label22 As Label = DirectCast(row.FindControl("Label22"), Label)
        Me.Response.Redirect("Select_seats.aspx?s_no=" & label22.Text.ToString & "&" & "journey=" & label6.Text & "&" & "seater=" & label4.Text & "&" & "sleeper=" & label2.Text & "&" & "service=" & lab5.Text.ToString)
    End If

这篇关于有什么不对的ASP.NET code ....? (数据网格+的ImageButton)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:25