我插入代码;
HTML:
<asp:Label ID="document" runat="server" Text="Document"></asp:Label>
<asp:TextBox ID="name" runat="server" AutoPostBack="true"></asp:TextBox>
<asp:Label ID="upload" runat="server" Text="Upload Document"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" multiple="true" Style="text-align: center;
margin-left: 50px;" Height="27px" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="UploadFile" CommandName="Add" />
<asp:DataList ID="datalist" runat="server" RepeatColumns="5" CellPadding="5" BorderWidth="25px"
CellSpacing="2" Font-Bold="True" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" GridLines="Both">
<HeaderTemplate>
<table>
<tr>
<th>
My Folder
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:TextBox ID="name" runat="server" EnableViewState="true"></asp:TextBox>
</td>
<td>
<asp:LinkButton ID="lnkDownload" Text="Download" CommandArgument='<%# Eval("Value") %>'
runat="server" OnClick="DownloadFile" />
</td>
<td>
<asp:LinkButton ID="lnkDelete" Text="Delete" CommandArgument='<%# Eval("Value") %>'
runat="server" OnClick="DeleteFile" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<ul class="pager">
<li class="previous"><a href="#">Previous</a></li>
<li class="next"><a href="#">Next</a></li>
</ul>
</FooterTemplate>
</asp:DataList>
VB:
Dim lsfilename As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim filePaths() As String = Directory.GetFiles(Server.MapPath("..\Fileupload\insert\"))
Dim files As List(Of ListItem) = New List(Of ListItem)
For Each filePath As String In filePaths
files.Add(New ListItem(Path.GetFileName(filePath), filePath))
Next
datalist.DataSource = files
datalist.DataBind()
End If
End Sub
Protected Sub UploadFile(ByVal sender As Object, ByVal e As EventArgs)
Dim fileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
FileUpload1.PostedFile.SaveAs((Server.MapPath("..\Fileupload\insert\") + name.Text))
lsfilename = name.Text
Response.Redirect(Request.Url.AbsoluteUri)
End Sub
Protected Sub DownloadFile(ByVal sender As Object, ByVal e As EventArgs)
Dim filePath As String = CType(sender, LinkButton).CommandArgument
Response.ContentType = ContentType
Response.AppendHeader("Content-Disposition", ("attachment; filename=" + Path.GetFileName(filePath)))
Response.WriteFile(filePath)
Response.End()
End Sub
Protected Sub DeleteFile(ByVal sender As Object, ByVal e As EventArgs)
Dim filePath As String = CType(sender, LinkButton).CommandArgument
File.Delete(filePath)
Response.Redirect(Request.Url.AbsoluteUri)
End Sub
Private Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
datalist.DataBind()
End Sub
但是,它不显示文件名以及如何编写上一个和下一个按钮代码。我想只插入9个文件,然后转到下一页。请帮助我。
谢谢,
答案 0 :(得分:0)
在datalist's
项目模板中设置文本框text
,如下所示
<asp:TextBox ID="name" runat="server" EnableViewState="true" Text='<%# Container.DataItem.ToString() %>'></asp:TextBox>