我有一个中继器控件来列出根文件夹中的所有子文件夹和文件。
<table border="1px solid " style="border-collapse: collapse;width: 90%;" cellspacing="3" cellpadding="3">
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand"
OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<tr>
<td>
<asp: Label ID="imagelabel"..../>// display image here
</td>
<td>
<asp:LinkButton ID="lnkFolder" runat="server" Text='<%# Eval("Name") %>' CommandName="Select"></asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="LinkButton1" runat="server" Text="Delete" CommandArgument='<%# Eval("Path") +"," + Eval("Type")%>'
CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete?')"></asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="LinkButton2" runat="server" Text="Edit" CommandArgument='<%# Eval("Path") + "," + Eval("Type") + "," + Eval("Name")%>'
CommandName="Edit"></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
在后面的代码中:
private void FillFileAndFolders(string virtualDirPath)
{
DataTable filesAndFolders = new DataTable();
filesAndFolders.Columns.Add("Name");
filesAndFolders.Columns.Add("Path");
filesAndFolders.Columns.Add("Type");
string rootPath = virtualDirPath;
if (Directory.Exists(rootPath))
{
string[] Directories = Directory.GetDirectories(rootPath);
for (int i = 0; i < Directories.Length; i++)
{
DirectoryInfo drinfo = new DirectoryInfo(Directories[i]);
DataRow dr = filesAndFolders.NewRow();
dr["Name"] = drinfo.Name;
dr["Path"] = drinfo.FullName;
dr["Type"] = "D";
filesAndFolders.Rows.Add(dr);
}
string[] files = Directory.GetFiles(rootPath);
for (int i = 0; i < files.Length; i++)
{
FileInfo fInfo = new FileInfo(files[i]);
DataRow dr = filesAndFolders.NewRow();
dr["Name"] = fInfo.Name;
dr["Path"] = fInfo.FullName;
dr["Type"] = "F";
filesAndFolders.Rows.Add(dr);
}
}
Repeater1.DataSource = filesAndFolders;
Repeater1.DataBind();
}
我想要的是:当它是Folder
--->时imagelabel.Text= "<img src='/folder.png'>"
;
否则当它是一个单一的file
----> imagelabel.Text= "<img src='/file.png'>"
;
我已经尝试了很多次,但似乎我无法imagelabel
通过中继器控件将该图像设置为。
帮助!!!