Asp listview declaration

<div style="overflow:auto;height:70px">
                        <asp:ListView ID="listview1" runat="server" OnItemCommand="listview1_ItemCommand">
                            <ItemTemplate>
                                <table border="0" cellpadding="0" cellspacing="0" width="120px">
                                    <tr>
                                        <td align="center">
                                            <span>
                                                <img src="images/101389-200.png" /></span>
                                            <asp:ImageButton ID="image" runat="server" Visible="false" ImageUrl='<%# Eval("MultiDocument_AttachmentPath") %>' Height="100px" Width="100px" />
                                            <asp:LinkButton ID="btndownload" runat="server" Text="Download" CommandName="imgBtn" ></asp:LinkButton>
                                        </td>
                                    </tr>
                                    <%--  <tr>
                                    <td align="center">
                                        <%# Eval("Text") %>
                                    </td>
                                </tr>--%>
                                </table>
                            </ItemTemplate>
                        </asp:ListView>
                    </div>

======================

  protected void listview1_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        if (e.CommandName == "imgBtn")
        {
            ImageButton img = (e.Item.FindControl("image") as ImageButton);
            var filePath = img.ImageUrl;
            Response.ContentType = ContentType;
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
            Response.WriteFile(filePath);
            Response.End();
        }
     
    }

Comments

Popular posts from this blog

Create Schema Using C# Asp .Net Dynamically.

How to set Transaction and Roll Back using Entity Framework in C# Code.

How to post image in blob using Windows Azure.