GridView中按钮的代码? [英] Code for Button in GridView?
问题描述
我在Asp.Net中具有GridView,具有三列,Id,名称,按钮.
后端:Access Db 2003
现在,我有一些通过上传"页面上传的PDF文件,该文件存储在〜/pdf/"文件夹中,每次用户上传图书时,其ID,名称和网址(例如,〜/pdf/test.pdf)都存储在数据库表名称"中TestTB.
目前,我使用Asp:Hyperlink和NavigateUrl重定向到PDF文件.
现在,我想删除超链接并使用图像按钮放置Asp:Button,并在用户单击时重定向到关联的pdf.
当前对每个文件使用手动重定向
回复.重定向(〜/pdf/test.pdf")
该怎么做?
Hi,
I have GridView in Asp.Net with Three Column , Id, Name, Button.
Back End : Access Db 2003
Now I have some PDF file uploaded by Upload page which stored in "~/pdf/" Folder, Every Time When User Upload the book , its Id, Name and Url (e.g. ~/pdf/test.pdf) stored in Database table Name TestTB.
Currently I Redirect with Asp:Hyperlink with NavigateUrl to PDF Files.
Now I want to Remove the Hyperlink and Place Asp:Button with Image Button and Redirect to associated pdf when user click.
Currently using Manual Redirect for Each File
Response. Redirect("~/pdf/test.pdf")
How to Do that?
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ADSource"
Width="910px" Font-Names="Calibri" Height="159px">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Sr No" SortExpression="Id" ItemStyle-HorizontalAlign="Center" >
<ItemStyle Width="50px"/>
</asp:BoundField>
<asp:BoundField DataField="NameofBook" HeaderText="Name of Book" SortExpression="NameofBook">
<ItemStyle Width="120px" HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="DescriptionBook" HeaderText="Description" SortExpression="DescriptionBook" >
<ItemStyle Width="550px" HorizontalAlign="Justify"/>
</asp:BoundField>
<asp:TemplateField HeaderText="Cover Page">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("ImageUrl")%>' Text="View Now"></asp:HyperLink>
</ItemTemplate>
<ItemStyle Width="60px" CssClass="coverpage" HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Read Now">
<ItemTemplate>
<asp:HyperLink ID="lnkViewLink" runat="server" NavigateUrl='<%# Eval("ViewLink")%>' Text="Read Now"></asp:HyperLink>
</ItemTemplate>
<ItemStyle Width="60px" CssClass="coverpage" HorizontalAlign="Center"/>
</asp:TemplateField>
<asp:ButtonField ShowHeader="True"
SortExpression="ViewLink" Text="Download" ButtonType="Button"
HeaderText="Download" />
</Columns>
<EmptyDataTemplate>
ImageUrl
</EmptyDataTemplate>
</asp:GridView>
推荐答案
检查本文
在ASP中使用SQL Server上载和下载文件. NET [ ^ ]
Check this article
Upload and Download Files with SQL Server in ASP.NET[^]
这篇关于GridView中按钮的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!