gridview 行内控件,事件为什么不执行RowCommand
点击删除按钮应该执行的事件,但是实际上没有执行
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName=="delJiaojie")
{
System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(e.CommandArgument.ToString()));
if (file.Exists)
{
file.Delete();
ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "message", "alert('删除成功')", true);
}
}
}
下面是后台添加删除按钮代码
--------------------编程问答-------------------- --------------------编程问答-------------------- 你前台页面有没有保存?
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate))
{
Panel p_jiaojie = e.Row.FindControl("p_jiaojie") as Panel;
ImageButton ib = new ImageButton();
ib.ID = "ibDelJiaojie";
ib.CommandName = "delJiaojie";
ib.CommandArgument = "attachment/" + drv.Jiaojieattachment;
ib.ImageUrl = "images/gtk-del.png";
ib.ToolTip = "删除上传文件";
ib.OnClientClick = "return confirm('确定删除?');";
p_jiaojie.Controls.Add(ib);
}
}
确认你前台和后台全保存了? --------------------编程问答-------------------- 、
应该不是前台页面的问题,我访问前台页面,已经能看到 这个在后台添加的删除按钮了,就是 点了 这个按钮 ,没有执行 里面的操作。没有进入RowCommand事件 --------------------编程问答-------------------- 今天怎么都是问GridView的删除问题的???? --------------------编程问答-------------------- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
===============>
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) {} --------------------编程问答-------------------- ImageButton 根据权限设置是否可见visible,看看页面的按钮
(e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate))
{
Panel p_jiaojie = e.Row.FindControl("p_jiaojie") as Panel;
ImageButton ib = e.Row.FindControl("ibDelJiaojie") ImageButton;
} --------------------编程问答-------------------- 断点调试,跟踪sql语句,在查询分析器中是否正常执行 --------------------编程问答--------------------
按钮已经在页面上呈现出来了,说明后台添加代码是执行了成功了,按钮的属性也是设置成功了。
但是,唯独按钮点击之后 没有触发RowCommand事件 --------------------编程问答-------------------- 还是没有解决 --------------------编程问答-------------------- CommandName是否一致? --------------------编程问答-------------------- 动态添加的好像是不行的,你需要在Init事件里添加才可以,建议你在模板列里面写,根据条件来删除,而不是根据条件来添加 --------------------编程问答--------------------
现在也只能先用着你的方案了,但是我觉得你的观点不太合理,每个模板列都添加,
第一,做了无谓的事情,本来就没有文件,显示删除白白浪费资源,对用户体验也不好。
补充:.NET技术 , ASP.NET