为什么找不到控件
我看书上写的,怎么找不到控件
private void dgrdReplies_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
LinkButton lbtnDeleteReply = (LinkButton)e.Item.FindControl( "lbtnDeleteReply ");
if(lbtnDeleteReply != null)
{
lbtnDeleteReply.Attributes.Add( "onclick " , "return confirm( '你真的要删除此回复吗? '); ");
}
}
------解决方案--------------------private void dgrdReplies_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
LinkButton lbtnDeleteReply = (LinkButton)e.Item.FindControl( "lbtnDeleteReply ");
if(lbtnDeleteReply != null)
{
lbtnDeleteReply.Attributes.Add( "onclick " , "return confirm( '你真的要删除此回复吗? '); ");
}
}
}