Image.ImageUrl not working (C#, asp.net)
I have the next code:
<asp:ListView ID="LV1" r开发者_StackOverflow中文版unat="server" DataSourceID="LinqDataSource">
<ItemTemplate>
<asp:Image ID="Image1" Width="100px" Height="100px" runat="server" />
//....and so on till the
</asp:ListView>
The code behind:
protected void checkTheImage()
{
foreach (ListViewItem item in LV1.Items)
{
((Image)item.FindControl("Image1")).ImageUrl = "~/noImage.jpg";
}
}
And page load:
protected void Page_Load(object sender, EventArgs e)
{
checkTheImage();
}
The problem is - the noImage.jpg is not display... why ?
not sure if your markup is ok, you should also have a closing ItemTemplate
tag somewhere... please update your markup.
just to try out things, does it work if you move the call of checkTheImage(); inside the Page_PreRender?
is there any place where you DataBind the ListView in your page life cycle?
May be you need to rebind the ListView.
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
LV1.DataBind();
checkTheImage();
}
}
精彩评论