datalist控件findcontrol查找控件方法的问题!!
aspx代码:
<ItemTemplate>
<table width= "748 " border= "1 " cellpadding= "4 " cellspacing= "0 " class= "addtable " style= "border-collapse:collapse ">
<tr>
<td colspan= "2 " class= "addwordt1 "> 编号: <%# Container.ItemIndex+1 %> | 邮箱: <a href= "mailto: <%# DataBinder.Eval(Container.DataItem, "eMail ") %> "> <%# DataBinder.Eval(Container.DataItem, "eMail ") %> </a> | QQ: <%#DataBinder.Eval(Container.DataItem, "qq ") %> | IP: <%# DataBinder.Eval(Container.DataItem, "userIp ") %> | 留言时间: <%# DataBinder.Eval(Container.DataItem, "Posttime ") %> </td>
</tr>
<tr>
<td align= "center " style= "width:120px; height:120px "> <img src= " <%# Eval( "userPic ") %> " alt= " "/> <br /> <br /> <%#Eval( "userName ") %> </td>
<td align= "left " valign= "top " style= "width:640px ">
<br />
<div class= "style1 "> <%#DataBinder.Eval(Container.DataItem, "Content ") %> </div>
<asp:Panel ID= "Panel1 " runat= "server " CssClass= "Restyle ">
管理员回复于: <asp:Label ID= "lblTime " runat= "server " Text= ' <%#Eval( "adminPosttime ") %> ' EnableViewState= "false " />
<br />
<%#Eval( "adminRecontent ") %>
</asp:Panel>
</td>
</tr>
<tr>
<td colspan= "2 " align= "left "> 客户端信息: <%#DataBinder.Eval(Container.DataItem, "userAgent ") %> </td>
</tr>
<tr>
<td colspan= "2 " align= "right ">
<asp:Button ID= "btnEdit " text= "回复 " CommandName= "edit " runat= "server " />
<asp:Button ID= "btnDelete " Text= "删除 " CommandName= "delete " runat= "server "/>
</td>
</tr>
</table>
</ItemTemplate>
cs代码
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label Lable1 = (Label)e.Item.FindControl( "lblTime ");
Panel Panel2 = (Panel)e.Item.FindControl( "Panel1 ");
if ( Label1.Text == " ")
{
Panel2.Visible = true;
}
}
}
意图:判断pannel内的lblTime控件text值是否为空。如果为空则 <ItemTemplate> 模板内的pannel控件不显示,如果不为空则显示。
代码调试后所有的pannel都显示是怎么回事?(有些lblTime的Text确实为空)!!
[解决办法]
Label Lable1 = (Label)e.Item.FindControl( "lblTime ");
((LinkButton)((Panel)e.Item.FindControl( "palDo ")).FindControl( "lbtop ")).Enabled=false;(我以前的代码)
你要这样找.先找到panel,然后在找label
[解决办法]
第二种方法
Label Lable1 = (Label)Panel2.FindControl( "lblTime ");
if ( Label1.Text == " ")
也是 Lable1 和 Label1
顶你个肺啊,考验大家的眼力吗?大哥,能copy的最好是不好键盘,
我以前设置cache的时候,发现总没作用,老为空,郁闷了一天,最后发现set和get的时候,用的变量字母有差别,