很奇怪的现象:嵌套了母板页的页面,其中DataList中控件隐藏的问题(大家帮个忙)
大概意思是这样:前台DataList 中的Label控件 "labIsPerfect "值为1时 ,则图片显示,为0,则图片隐藏
(1)前台页面 .aspx
<asp:DataList ID= "dlPost " runat= "server " Width= "855px ">
<ItemTemplate>
<asp:Image runat= "server " ID= "imgOK " ImageUrl= "~/Images/jing.gif " />
<asp:Label ID= "labIsPerfect " runat= "server " Text= ' <%# Eval( "IsPerfect ") %> ' > </asp:Label>
</ItemTemplate>
</asp:DataList>
(2)后台的.cs中
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TopicBind();
}
}
private void TopicBind()
{
//此处省略,绑定数据等
dlPost.DataSource = dt;
dlPost.DataBind();
foreach (DataListItem item in aa.Items)
{
Image imgOK = (Image)item.FindControl( "imgOK ");
Label labIsPerfect = (Label)item.FindControl( "labIsPerfect ");
if (Convert.ToInt32(labIsPerfect.Text) == 1)
{
imgOK.Visible = true;
}
else
{
imgOK.Visible = false;
}
}
}
代码应该没有什么问题,
在不嵌套母板页的页面中,显示正常(但我的页面肯定是要放在母板页中的) <