0
我有一個帶有GridView控件的頁面。ASP.NET - 在頁面加載時加載LIstBox控件
在GridView的還有包含ListBox控件的TemplateField:
<asp:TemplateField HeaderText="Uploaded Files">
<ItemTemplate>
<asp:ListBox ID="ListBoxFiles" runat="server"></asp:ListBox>
</ItemTemplate>
</asp:TemplateField>
我需要填充這個列表框與文件的列表文件夾中加載網頁時在服務器上。我對如何做到這一點感到不知所措。
我可以實現與標籤類似的效果:背後
Public Function GetFiles(param As String)
GetFiles = ""
Try
Dim filePaths() As String = Directory.GetFiles(Server.MapPath("~/Uploads/") & Session("LastFirst") & " - " & Session("StudentUID") & "/" & param & "/")
For Each filePath As String In filePaths
GetFiles = GetFiles & "<br/>" & Path.GetFileName(filePath)
Next
GetFiles = Right(GetFiles, Len(GetFiles) - 5)
Catch
End Try
End Function
<asp:TemplateField HeaderText="Uploaded Files">
<ItemTemplate>
<asp:ListBox ID="ListBoxFiles" runat="server"></asp:ListBox>
<asp:Label ID="LabelFiles" runat="server" Text='<%#GetFiles(Eval("DocDescription")) %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
用下面的代碼,但我希望用戶必須選擇要刪除的文件的能力。
如何在頁面加載時填充ListBox?
這正是我所需要的東西。謝謝! –