怎么把DataGrid.DeleteCommand事件在付给DataGrid.DeleteCommand
这是DataGrid.DeleteCommand的事件
private void dgProductList_DeleteCommand(object source, DataGridCommandEventArgs e)
{
ProductDB tdb = new ProductDB();
ProductDetails productDetails = tdb.GetProductDetails(int.Parse(this.dgProductList.DataKeys[e.Item.ItemIndex].ToString()));
try
{
File.Delete(base.Server.MapPath("../" + this.config.Path + "Upload/" + productDetails.ProductImg));
File.Delete(base.Server.MapPath("../" + this.config.Path + "Upload/" + productDetails.ThumbnailImg));
if (productDetails.RelatedImgs != "")
{
string[] strArray = productDetails.RelatedImgs.Split(new char[] { ',' });
for (int i = 0; i < strArray.Length; i++)
{
File.Delete(base.Server.MapPath("../" + this.config.Path + "Upload/relatedImgs/" + strArray[i].ToString()));
}
}
}
catch
{
}
tdb.ChangeProductStatus(int.Parse(this.dgProductList.DataKeys[e.Item.ItemIndex].ToString()), -1);
new ShoppingCartDB().RemoveItem(int.Parse(this.dgProductList.DataKeys[e.Item.ItemIndex].ToString()));
new FavoriteDB().DeleteFavoriteByProductID(int.Parse(this.dgProductList.DataKeys[e.Item.ItemIndex].ToString()));
CategoryDB ydb = new CategoryDB();
this.SearchProducts();
}
我想把dgProductList_DeleteCommand加载给DataGrid.DeleteCommand
private void InitializeComponent()
{
this.dgProductList.add_DeleteCommand(new DataGridCommandEventHandler(this, (IntPtr)this.dgProductList_DeleteCommand));
}
但是报错编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
编译器错误消息: CS0428: 无法将方法组“dgProductList_ItemCommand”转换为非委托类型“System.IntPtr”。您是要调用方法吗?
源错误:
--------------------编程问答-------------------- --------------------编程问答-------------------- CS0428: 无法将方法组“dgProductList_ItemCommand”转换为非委托类型“System.IntPtr
你把这个方法里的内容用一个新方法封装。
然后直接输入方法名
这样调不是很好。
要调用两次?
补充:.NET技术 , ASP.NET