增加了一下方法:
private void Mydg_ItemCreated(object sender,System.Web.UI.WebControls.DataGridPageChangedEventHandler e)
{
ListItemType itemType = e.Item.ItemType;
if((itemType == ListItemType.Item||itemType == ListItemType.AlternatingItem))
{
LinkButton myDeleteButton = new LinkButton();
myDeleteButton = (LinkButton)e.Item.Cells[14].Controls[0];
myDeleteButton.Attributes.Add("onclick","return confirm('sure?')");
}
}
再在private void InitializeComponent()里面增加:
this.Mydg.ItemCreated += new System.Web.UI.WebControls.DataGridCommandEventArgs(this.Mydg_ItemCreated);
出现错误提示:
c:\inetpub\wwwroot\Raises\Page\QueryRaises.aspx.cs(258): 无法将类型“System.Web.UI.WebControls.DataGridCommandEventArgs”隐式转换为“System.Web.UI.WebControls.DataGridItemEventHandler”
c:\inetpub\wwwroot\Raises\Page\QueryRaises.aspx.cs(258): 在不带括号的情况下引用了方法“Raises.Page.QueryRaises.Mydg_ItemCreated(object, System.Web.UI.WebControls.DataGridCommandEventArgs)”
---------------------------
错在哪里呢?
參考答案:我这儿有一段代码你可以参考一下:
private void buyerlist_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
((LinkButton)(e.Item.Cells[5].Controls[0])).Attributes.Add("onclick","return confirm('你确认删除吗?');");
}
}