我一直在尝试使用 webusercontrol、delegate 和 ADO 创建动态控制面板。即使我写了删除和编辑的委托,我也面临“GridView 'GridView1' 触发的事件 RowDeleting 没有被处理。”问题。有人可以帮我吗这是我的代码
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = this.DataSource;
GridView1.DataBind();
GridView1.DataKeyNames = new string[] { this.DataKeyNames };
}
public object DataSource { get; set; }
public string DataKeyNames { get; set; }
public event GridHander RowDeleting;
public event GridHander RowSawing;
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow gvr = ((LinkButton)e.CommandSource).Parent.Parent as GridViewRow;
int rowIndex = gvr.RowIndex;
object id = GridView1.DataKeys[rowIndex].Value;
switch (e.CommandName)
{
case "Edit":
GridView1.EditIndex = rowIndex;
break;
case "Delete":
if (RowDeleting != null)
{
GridEventArgs args = new GridEventArgs()
{
row=gvr,
id=id,
rowIndex=rowIndex
};
RowDeleting.Invoke(e.CommandSource, args);
}
break;
case"Save":
if (RowSawing != null)
{
GridEventArgs args = new GridEventArgs()
{
row = gvr,
id = id,
rowIndex = rowIndex
};
RowSawing.Invoke(e.CommandSource, args);
}
GridView1.EditIndex = -1;
break;
case "Cancel":
GridView1.EditIndex = -1;
break;
default:
break;
}
}
}
//我的网络表单
ublic partial class CategoryControlPanel : System.Web.UI.Page
{
CategoryResposite _categoryResposite=new CategoryResposite();
protected void Page_Load(object sender, EventArgs e)
{
ControlPanel.DataSource = _categoryResposite.ListCategories();
ControlPanel.RowDeleting += ControlPanel_RowDeleting;
ControlPanel.RowSawing += ControlPanel_RowSawing;
}
void ControlPanel_RowSawing(object sender, GridEventArgs e)
{
throw new NotImplementedException();
}
void ControlPanel_RowDeleting(object sender, GridEventArgs e)
{
_categoryResposite.DeleteCategories(Convert.ToInt32(e.id));
}