为什么我的转发器控件中的图像没有显示出来 [英] Why my image in a repeater control is not getting displayed
本文介绍了为什么我的转发器控件中的图像没有显示出来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用了转发器控件来查看文件夹中的所有图像。但图像没有显示出来。请帮帮我。
这是我的代码..
I have used a repeater control to view all images from a folder. but images are not getting displayed. can u help me please.
This is my code..
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("~/" + "XML/album.xml"));
XmlNodeList nodelist = xmldoc.GetElementsByTagName("Album");
DataTable dt = (DataTable)Session["dt"];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < nodelist.Count; i++)
{
string val = e.CommandArgument.ToString();
string attr = nodelist[i].Attributes["Name"].Value;
if (attr == val)
{
List<string> images = new List<string>();
DirectoryInfo di = new DirectoryInfo(Server.MapPath("") + "\\" + val + "\\" + "Images\\");
int count = di.GetFiles().Length;
//all Images in folder add in datarow and bind to repeater control
DataTable imgdt = new DataTable();
for (int j = 0; j < count; j++)
{
string imgpath=nodelist[i].InnerText;
DirectoryInfo directoryInfo = new DirectoryInfo(imgpath);
FileInfo[] fileInfo = directoryInfo.GetFiles();
images.Add(fileInfo[j].Name);
}
Repeater2.DataSource = images; // i am getting image name here
Repeater2.DataBind();
}
}
}
}
这个设计视图。
this the desgin view.
<asp:Repeater ID="Repeater2" runat="server" onitemcommand="Repeater1_ItemCommand">
<ItemTemplate>
<td>
<asp:Image ID="Image1" runat="server" ImageUrl="<%# Container.DataItem %>"/>
</td>
</ItemTemplate>
</asp:Repeater>
推荐答案
你看到什么转发器呈现?每行HTML中呈现的路径是什么?该路径是否适合图像?我猜它不是。请告诉我。
Hi,
What do you see when the repeater is rendered? What path is being rendered in the HTML for each row? Is that path correct for an image? I am guessing it isn't. Please let me know.
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("~/" + "XML/album.xml"));
XmlNodeList nodelist = xmldoc.GetElementsByTagName("Album");
DataTable dt = (DataTable)Session["dt"];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < nodelist.Count; i++)
{
string val = e.CommandArgument.ToString();
string attr = nodelist[i].Attributes["Name"].Value;
if (attr == val)
{
List<string> images = new List<string>();
DirectoryInfo di = new DirectoryInfo(Server.MapPath("") + "\\Gallary\\" + val + "\\" + "Images\\");
int count = di.GetFiles().Length;
//all Images in folder add in datarow and bind to repeater control
DataTable imgdt = new DataTable();
imgdt.Columns.Add("ImagesFolder", typeof(string));
for (int j = 0; j < count; j++)
{
DataRow dr = imgdt.NewRow();
string imgpath = nodelist[i].InnerText;
//bind folder images to datarow here.
dr["ImagesFolder"] = nodelist[i].InnerText;
imgdt.Rows.Add(dr);
DirectoryInfo directoryInfo = new DirectoryInfo(imgpath);
FileInfo[] fileInfo = directoryInfo.GetFiles();
string fullpath = "~\\Gallary\\" + val + "\\" + "Images\\" + fileInfo[j].Name;
images.Add(fullpath);
}
Repeater2.DataSource = images;
Repeater2.DataBind();
}
}
}
}</string></string>
这篇关于为什么我的转发器控件中的图像没有显示出来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文