如何通过转发器控件中的链接按钮从数据库下载文档 [英] how to download a document from the database via a link button in a repeater control

查看:71
本文介绍了如何通过转发器控件中的链接按钮从数据库下载文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过使用转发器控件中的链接按钮从与特定员工相关的数据库中下载文档.证书是我要下载的,因为这是证书中文件的名称.数据库.

I want to download a document from the database related to a specific employee by making use of a link button that is found inside a repeater control.The certificate is what I want to download as this is the name of the file inside the database.

这是我的中继器控件代码:

This is my code for my repeater control:

<asp:Repeater ID="RepeaterEmployee" runat="server" OnItemCommand="RepeaterEmployee_ItemCommand">            
    <ItemTemplate>
        <table runat="server" class="table table-default table-striped table-bordered table-condensed">
            <tr><td colspan="2" style="text-align:center;" ><asp:Image ID="Image1" runat="server" ImageAlign="Middle"  ImageUrl='<%# Eval("Photo") %>' /></td></tr>
            <tr>
                <td style="vertical-align:middle;">
                    <%--<asp:Image ID="EmployeePhoto" runat="server" ImageAlign="AbsMiddle"  ImageUrl='<%# Eval("Photo") %>' />--%>
                </td>
                <td>
                    <table runat="server" style="width:100%;">
                        <tr>
                            <td><b>First Name:</b></td>
                            <td><asp:Label ID="FirstName" runat="server" Text='<%#Eval("FirstName") %>'></asp:Label></td>
                        </tr>
                        <tr>
                            <td><b>Last Name:</b></td>
                            <td><asp:Label ID="lblLastName" runat="server" Text='<%#Eval("LastName") %>'></asp:Label></td>
                        </tr>
                        <tr>
                            <td><b>Employee Code:</b></td>
                            <td><asp:Label ID="lblCode" runat="server" Text='<%#Eval("Code") %>'></asp:Label></td>
                        </tr>                                      
                            <td><b>Right Eye Corr Day/Night:</b></td>
                            <td><asp:Label ID="lblRightEyeCorrDayNight" runat="server" Text='<%#Eval("RightEyeCorrDayNight") %>'></asp:Label></td>
                        </tr>
                        <tr>
                            <td><b>Visual Field Left Day/Night:</b></td>
                            <td><asp:Label ID="lblVisualFieldLeftDayNight" runat="server" Text='<%#Eval("VisualFieldLeftDayNight") %>'></asp:Label></td>
                        </tr>
                        <tr>
                            <td><b>Visual Field Right Day/Night:</b></td>
                            <td><asp:Label ID="lblVisualFieldRightDayNight" runat="server" Text='<%#Eval("VisualFieldRightDayNight") %>'></asp:Label></td>
                        </tr>
                        <tr>
                            <td><b>Colour Vision Day/Night:</b></td>
                            <td><asp:Label ID="lblColourVisionDayNight" runat="server" Text='<%#Eval("ColourVisionDayNight") %>'></asp:Label></td>
                        </tr>
                        <tr>
                            <td><b>Date Tested:</b></td>
                            <td><asp:Label ID="lblDateTested" runat="server" Text='<%#Eval("DateTested") %>'></asp:Label></td>
                        </tr>
                        <tr>
                            <td><b>Medical Report:</b></td>
                            <td>
                                 <asp:LinkButton ID="LinkButton1" runat="server" OnCommand="LinkButton1_Command" OnClick="LinkButton1_Click" CommandArgument='<%# Eval("Certificate") %>' CommandName="download">Download</asp:LinkButton>
                            </td>
                        </tr>         
                    </table>
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:Repeater>

推荐答案

代替链接按钮,创建简单的定位标记,并在绑定转发器的同时在标记源中绑定文档名称
例如-
"
< a > href ="/images/myw3schoolsimage.jpg" ID ="LinkBut​​ton1" runat =服务器" target ="_ blank"下载>"

Instead of the link button create simple anchor tag and bind the document name in the source of the tag while binding the repeater
e.g.-
"
<a> href="/images/myw3schoolsimage.jpg" ID="LinkButton1" runat="server" target="_blank" download>"

use可以使用项目数据绑定事件来绑定按钮的href(文档的路径).
如果它不起作用,请回复我

use can use the item data-bound event to bind the href(path of the document) of the button.
Please reply me if it is not working

这篇关于如何通过转发器控件中的链接按钮从数据库下载文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆