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
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
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)