DataList里的客户端控件响应脚本的问题
<asp:DataList ID= "dlMenuBig " runat= "server " OnItemDataBound= "dlMenuBig_ItemDataBound " Width=100%>
<ItemTemplate>
<table cellpadding= "0 " cellspacing= "0 " width=100%>
<tr>
<td valign=middle>
<img src= "../../images/plus.gif " id=img1 runat=server/>
</td>
</tr>
<tr>
<td width=100% id=td1 style= "display:none; " runat=server>
内容
</td>
</tr>
</table> 我想在单击img的时候把下面的td1的显示出来
然后我在dlMenuBig_ItemDataBound里这样写
protected void dlMenuBig_ItemDataBound(object sender, DataListItemEventArgs e)
{
HtmlImage img = (HtmlImage)e.Item.FindControl( "img1 ");
HtmlTableCell td1 = (HtmlTableCell)e.Item.FindControl( "td1 ");
img.Attributes.Add( "onclick ", "document.getElementById( ' " + td1.UniqueID + " ').style.display= ' ' ");
}
但单击img的时候出现脚本错误(提示找不到对象),请问如何解决?急
------解决方案-------------------- 改成:
img.Attributes.Add( "onclick ", "document.getElementById( ' " + td1.ClientID+ " ').style.display= ' ' ");
试试看