Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi y'all,

I'm still new on using Vb.net and its pretty easy to handle the main gridview rowcommand event. However, i still dont know how to access the child gridview row command. whenever I use the keyword 'AddHandler gvFiles.RowCommand, AddressOf gvFiles_RowCommand' it will cause an error 'does not have signature compatible with delegate' The codes are as below.

VB
Private Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim lbltype As Label = e.Row.FindControl("lblType_HWSW")
            Dim LinkCalendar As LinkButton = e.Row.FindControl("LinkCalendar")

            If (lbltype.Text = "sw") Then
                LinkCalendar.Visible = False
            End If

            Dim filePaths() As String = Directory.GetFiles(("C:\Uploads"))
            Dim files As List(Of ListItem) = New List(Of ListItem)
            For Each filePath As String In filePaths
                files.Add(New ListItem(Path.GetFileName(filePath), filePath))
            Next

            Dim gvFiles As GridView = e.Row.FindControl("GridView2")
            AddHandler gvFiles.RowCommand, AddressOf gvFiles_RowCommand 'this line is causing me an error and unable to access gvFiles_rowcommand below. Obviously I did something wrong.

            gvFiles.DataSource = files
            gvFiles.DataBind()

        End If
    End Sub


VB
Private Sub gvFiles_RowCommand(sender As Object, e As GridViewRowEventArgs)
        Dim filePath As String = CType(sender, LinkButton).CommandArgument
        Response.ContentType = ContentType
        Response.AppendHeader("Content-Disposition", ("attachment; filename=" + Path.GetFileName(filePath)))
        Response.WriteFile(filePath)
        Response.End()
    End Sub


sorry for my bad English and hope someone out there can help me.
Posted

1 solution

The e parameter should be of type GridViewCommandEventArgs

regs

ron O.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900