首页 > 解决方案 > 下载在网格视图中检查的文件的更好方法

问题描述

我有一个网格视图,其中有一列复选框,然后是几列数据。选择一行时,将显示其对应的图像。任何行都可以在不被选中的情况下进行检查,当单击下载按钮时,应下载所有检查了相应行的图像。现在我有一个 for 循环遍历每一行并找到复选框并查看它是否被选中,这需要太长时间。选中复选框时,有没有办法访问相应行的数据?

For Each row As GridViewRow In gv1.Rows
  Dim chkBox As CheckBox = TryCast(row.FindControl("cBox"), CheckBox)
  If chkBox.Checked Then
    Dim full = row.Cells(1).Text & "B" & row.Cells(3).Text
    IO.File.Copy(serv & full & ".TIF", Path.Combine(temp, full & ".TIF"), True)
  End If
Next

标签: javascriptcssasp.netvb.netgridview

解决方案


这对我来说非常有效,非常有效。是 IO 副本花费了太长时间。

Using zip As New ZipFile()
        zip.AlternateEncodingUsage = ZipOption.AsNecessary
        zip.AddDirectoryByName("Drawings")
        For Each row As GridViewRow In gv1.Rows
            If TryCast(row.FindControl("cBox"), CheckBox).Checked Then
                found = True
                Dim filepath = serv & row.Cells(1).Text & "B" & row.Cells(3).Text & ".TIF"
                zip.AddFile(filepath, "Drawings")
            End If
        Next
        If found Then
            Response.Clear()
            Response.BufferOutput = False
            Dim zipname As String = [String].Format("Drawings_{0}.zip", DateTime.Now.ToString("yyyy-MM-dd-HH:mm:ss"))
            Response.ContentType = "application/zip"
            Response.AddHeader("content-disposition", "attachment; filename=" + zipname)
            zip.Save(Response.OutputStream)
            Response.End()
        Else
            reSetup()
        End If
    End Using

推荐阅读