Down Load Files in Gridview using VB.NET................................................

Unknown | 6:37 AM |

<asp:GridView runat="server" ID="gridloadingdownload" Width="99%" DataKeyNames="attachdoc_id"
                    ShowHeaderWhenEmpty="true" AutoGenerateColumns="false" BorderColor="LightSkyBlue"
                    BorderWidth="1px">
                    <Columns>
                   
                        <asp:BoundField HeaderText="FileName" DataField="Filename" ItemStyle-Wrap="true">
                            <HeaderStyle BackColor="LightSkyBlue" Font-Bold="False" ForeColor="Black" HorizontalAlign="Left"
                                BorderColor="LightSkyBlue" BorderWidth="1px" />
                            <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="400Px" Wrap="true" BorderColor="LightSkyBlue" />
                        </asp:BoundField>
                        <asp:ButtonField ButtonType="Link" HeaderText="Download" Text="Download" CommandName="Download">
                            <HeaderStyle BackColor="LightSkyBlue" Font-Bold="False" ForeColor="Black" HorizontalAlign="Center"
                                BorderColor="LightSkyBlue" BorderWidth="1px" />
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Top" Width="30px" BorderColor="LightSkyBlue" />
                        </asp:ButtonField>
                    </Columns>
                </asp:GridView>




Private Sub gridloadingdownload_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gridloadingdownload.RowCommand
        Try
            If e.CommandName.ToString() = "Download" Then
                Dim id As Integer
                ' Response.Redirect("DownLoadForm.aspx")
                'lblClassID.Text = grdClasses.DataKeys(Convert.ToInt32(e.CommandArgument)).Value.ToString()
                id = Convert.ToInt64(gridloadingdownload.DataKeys(Convert.ToInt32(e.CommandArgument)).Value.ToString())
                Dim dtExcel = New System.Data.DataTable()
                dtExcel = DataConnect.GetInstance.GetDt("Select * from po_attachment where po_attachment_id=" & id)
                If dtExcel IsNot Nothing Then
                    Response.Clear()
                    Response.ContentType = "application/x-unknown"
                    Response.AppendHeader("Content-Disposition", "attachment; filename=" & dtExcel(0)("file_name").ToString())
                    Response.BinaryWrite(DirectCast(dtExcel(0)("file_content"), Byte()))
                End If
            End If
            hdnpackId.Value = "0"
            hdntypeid.Value = "0"
            cmbPFEPLabel1.Items.Clear()
            fillNLOadCombos()
        Catch ex As Exception
     
        End Try
    End Sub

Category:

About http://dotnetvisual.blogspot.in/:
DOT NET TO ASP.NET is a web application framework marketed by Microsoft that programmers can use to build dynamic web sites, web applications and web services. It is part of Microsoft's .NET platform and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime, allowing programmers to write ASP.NET code using any Microsoft .NET language. create an application very easily ....