我有一个通用的处理程序只有一个形象出现在列表视图
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/jpeg,png,jpg,gif";
int newsId = int.Parse(context.Session["newsId"].ToString());
int FK_UnitId = int.Parse(context.Session["UserData"].ToString());
Managers.Photo p = new Managers.Photo();
string dirPath = ConfigurationManager.AppSettings.GetValues("ThePath").First() + "/" + "NewsImages" + "/" + "UnitNum" + FK_UnitId.ToString() + "_" + "NewsNum" + newsId.ToString() + "/";
string dirPathForTextFiles = ConfigurationManager.AppSettings.GetValues("ThePath").First() + "/" + "NewsTextFiles" + "/" + "UnitNum" + FK_UnitId.ToString() + "_" + "NewsNum" + newsId + "/";
DataTable dt = p.GetAllPhotos(newsId);
List<string> l = new List<string>(dt.Rows.Count);
byte[] b = null;
FileStream f;
try
{
for (int i = 0; i < dt.Rows.Count; i++)
{
l.Add(dirPath + dt.Rows[i]["photoName"].ToString());
f = new FileStream(l[i].ToString(), FileMode.Open, FileAccess.ReadWrite);
b = new byte[f.Length];
f.Read(b, 0, b.Length);
context.Response.OutputStream.Write(b, 0, b.Length);
context.ClearError();
f = null;
b = null;
}
}
catch (IOException e)
{
string message = e.Message;
}
}
和我的网页上的列表视图:在cs文件中包含
Session.Add("newsId", newsId);
string dirPath =ConfigurationManager.AppSettings.GetValues("ThePath").First() + "/" + "NewsImages" + "/" + "UnitNum" + FK_UnitId.ToString() + "_" + "NewsNum" + newsId + "/";
string dirPathForTextFiles =ConfigurationManager.AppSettings.GetValues("ThePath").First() + "/" + "NewsTextFiles" + "/" + "UnitNum" + FK_UnitId.ToString() + "_" + "NewsNum" + newsId + "/";
DataTable dt = p.GetAllPhotos(int.Parse(newsId));
List<string> l = new List<string>(dt.Rows.Count);
for (int i = 0; i < dt.Rows.Count; i++)
{
l.Add(dirPath + dt.Rows[i]["photoName"].ToString());
}
lv_showImages.DataSource = l;
lv_showImages.DataBind();
我的源
<asp:ListView ID="lv_showImages" GroupItemCount="4" runat="server">
<ItemTemplate>
<asp:Image ID="img_newsImage" Height="100px" Width="100px" runat="server ImageUrl ='<%# "RetreiveImage.ashx" %>' />
</ItemTemplate>
</asp:ListView>`
现在我的问题:
当列表有虽然我调试了我的处理程序,并且我发现字节数组b的长度在循环中有所不同,但这意味着它应该写入不同的图像,而不是重复第一张图片的图片数量,我不知道为什么第一张图片才出现。
您是否使用过? –
Alex
2010-08-25 13:13:10