我是一名新的 ASP.NET 开发人员,我正在尝试开发一个名为 Useful Library 的页面,该页面将包含许多内容,例如有用的演示文稿和 pdf 文档。我在服务器中有一个名为(Useful Resources)的文件夹,我将所有有用的演示文稿和文档都放入其中。我的数据库中有下表:
UsefulResources Table: ID, Category, Title, URL, Uploaded Date, Hits
设计这张表的原因是为了组织资源。我现在希望能够浏览或下载这些文档。***例如,我有一个名为 (AP Presentation) 的演示文稿,它具有:***ID = 5 和 URL = AP Prsentation.pptx******
我的 ASP.NET 代码:
<asp:HyperLinkField DataNavigateUrlFields="ID,URL"
DataNavigateUrlFormatString="Useful Resources/URL={0}"
DataTextField="Title" HeaderText="Title" />
这部分有问题,我不知道如何修复它才能打开或下载此演示文稿,那么该怎么做呢?
供您参考,该页面名为(Library.aspx),我没有任何代码隐藏
更新:
我现在拥有的链接如下:pmvt/msa/pssp/Useful%20Resources/ID=5
顺便说一句,这是一个基于 Intranet Web 的应用程序,因此您将无法使用此链接访问它。
我收到以下错误:
更新#2: 这是我的 SqlDataSource 的 ASP.NET 代码:
<asp:SqlDataSource ID="Sql_Reports" runat="server"
ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT [ID], [Title], [URL], [UploadedDate] FROM [UsefulResources] WHERE ([Category] = @Category) ORDER BY [UploadedDate] DESC">
<SelectParameters>
<asp:ControlParameter ControlID="Label1" Name="Category" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="Sql_Reports" ForeColor="#333333" GridLines="None"
Width="100%">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#E3EAEB" />
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title">
<ItemStyle HorizontalAlign="Center" Wrap="False" Width="100px" />
</asp:BoundField>
<asp:HyperLinkField DataNavigateUrlFields="URL"
DataNavigateUrlFormatString="Useful Resources?URL={0}"
DataTextField="Title" HeaderText="Title" />
<asp:BoundField DataField="UploadedDate" DataFormatString="{0:MMM yyy}" HeaderText="UploadedDate"
SortExpression="UploadedDate">
<ItemStyle HorizontalAlign="Center" Wrap="False" Width="100px" />
</asp:BoundField>
</Columns>
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
我仍然得到链接为pmvt/msa/pssp/Useful%20Resources/?URL=Electrical%20safety.ppt。我应该怎么做才能从该链接中删除(?URL=)以使链接正常工作。
更新#2:
以下是在数据库中使用其数据创建表的脚本:
/****** Object: Table [dbo].[UsefulResources] Script Date: 08/06/2012 07:08:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[UsefulResources](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Category] [varchar](max) NULL,
[Title] [varchar](max) NULL,
[URL] [nvarchar](max) NULL,
[UploadedDate] [datetime] NULL,
[Hits] [int] NULL,
CONSTRAINT [PK_UsefulResources] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[UsefulResources] ON
INSERT [dbo].[UsefulResources] ([ID], [Category], [Title], [URL], [UploadedDate], [Hits]) VALUES (1, N'PowerPoint Presentations', N'PMOD', N'Electrical safety.ppt', CAST(0x0000A0A000000000 AS DateTime), 1)
INSERT [dbo].[UsefulResources] ([ID], [Category], [Title], [URL], [UploadedDate], [Hits]) VALUES (2, N'Word Documents', N'Fire Drill Evaluation', N'Fire Drill Evaluation.docx', CAST(0x0000A0A300000000 AS DateTime), 1)
SET IDENTITY_INSERT [dbo].[UsefulResources] OFF