【发布时间】:2014-11-17 08:27:13
【问题描述】:
我正在使用 CommandField 删除图像按钮,但它不起作用。这是我尝试过的sn-p:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer;
int indx = row.RowIndex;
using (Property_dbDataContext context = new Property_dbDataContext())
{
if (e.CommandName == "Delete")
{
var delete = (from a in context.Property_basics where a.prop_id == GridView1.Rows[indx].Cells[0].Text select a).Single();
delete.delete_status = 1;
context.SubmitChanges();
GridView1.DeleteRow(indx);
}
}
}
.aspx:
<asp:CommandField ButtonType="Image" HeaderText="Delete" DeleteImageUrl="~/wp-content/themes/realia/assets/img/500px-Delete_Icon2.png" ShowDeleteButton="True" />
它显示的异常是:
无法将“System.Web.UI.WebControls.ContentPlaceHolder”类型的对象转换为类型 'System.Web.UI.WebControls.GridViewRow'。
【问题讨论】: