日期:2014-05-19  浏览次数:20517 次

只有点击两次按钮才能弹出对话框!请问是怎么回事呢?
我用DataGrid控件来显示信息,在每行信息后面有个按钮,当我点击按钮时就会弹出新窗体。

我在ItemCommand事件中写了如下代码:

Button   bt=(Button)e.Item.FindControl( "dgBarcodeInput ");
bt.Attributes.Add( "onclick ",   "openform(); ");

现在出现问题:只有点击两次按钮才能弹出对话框!请问是怎么回事呢?   应该如何解决啊?谢谢!

------解决方案--------------------
我在ItemCommand事件中写了如下代码:

Button bt=(Button)e.Item.FindControl( "dgBarcodeInput ");
bt.Attributes.Add( "onclick ", "openform(); ");
======================》
你在ItemCommand事件才加上onclick事件,当然第一次点击的时候没有加拉,自然不会执行
要把这一段
Button bt=(Button)e.Item.FindControl( "dgBarcodeInput ");
bt.Attributes.Add( "onclick ", "openform(); ");
放在ItemDataBound里面

------解决方案--------------------
private void dgrdTitles_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item|| e.Item.ItemType == ListItemType.AlternatingItem))
{
Button bt=(Button)e.Item.FindControl( "dgBarcodeInput ");
bt.Attributes.Add( "onclick ", "openform(); ");
}
}