我用DataGrid控件来显示信息,在每行信息后面有个按钮,当我点击按钮时就会弹出新窗体。我在ItemCommand事件中写了如下代码:Button bt=(Button)e.Item.FindControl("dgBarcodeInput");
bt.Attributes.Add("onclick", "openform();");现在出现问题:只有点击两次按钮才能弹出对话框!请问是怎么回事呢? 应该如何解决啊?谢谢!
bt.Attributes.Add("onclick", "openform();");现在出现问题:只有点击两次按钮才能弹出对话框!请问是怎么回事呢? 应该如何解决啊?谢谢!
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
BindOnInit();
}private void BindLoad()
{
if(ddlarray.Items[0].Value!="0")
{
dv=Bind();
dgProduct.DataSource=dv;
dgProduct.DataKeyField="Pid";
dgProduct.DataBind(); }}Bind();是返回一个DataView!
bt.Attributes.Add("onclick", "openform();");
======================》
你在ItemCommand事件才加上onclick事件,当然第一次点击的时候没有加拉,自然不会执行
要把这一段
Button bt=(Button)e.Item.FindControl("dgBarcodeInput");
bt.Attributes.Add("onclick", "openform();");
放在ItemDataBound里面
未将对象引用设置到对象的实例的错误,这句话报错:bt.Attributes.Add("onclick", "openform();");
{
if(e.Item.ItemType == ListItemType.Item|| e.Item.ItemType == ListItemType.AlternatingItem))
{
Button bt=(Button)e.Item.FindControl("dgBarcodeInput");
bt.Attributes.Add("onclick", "openform();");
}
}