情况1:
使用dataSource绑定的时候使用一个页面变量,GridViewFlow_RowDeleting先执行,紧接着SqlDataSourceFlow_Deleting
private int rowIndex;
protected void GridViewFlow_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
rowIndex = e.RowIndex;
}
protected void SqlDataSourceFlow_Deleting(object sender, SqlDataSourceCommandEventArgs e)
{
e.Command.Parameters["v_spfabh"].Value = GridViewFlow.DataKeys[rowIndex]["spfabh"].ToString();
e.Command.Parameters["v_qztz"].Value = GridViewFlow.DataKeys[rowIndex]["qztz"].ToString();
e.Command.Parameters["v_hztz"].Value = GridViewFlow.DataKeys[rowIndex]["hztz"].ToString();
e.Command.Parameters["v_gwbh"].Value = GridViewFlow.DataKeys[rowIndex]["gwbh"].ToString();
e.Command.Parameters["v_gzlx"].Value = GridViewFlow.DataKeys[rowIndex]["gzlx"].ToString();
e.Command.Parameters["v_czr"].Value = sysUser.Name;
}
情况2:使用tableAdapter
protected void GridViewApproval_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
DataSetClass.ApprovalStateDataTable dt = new DataSetClass.ApprovalStateDataTable();
DataSetClassTableAdapters.ApprovalStateTableAdapter ta = new DataSetClassTableAdapters.ApprovalStateTableAdapter();
ta.P_DELCONTRACTSTATE(GridViewApproval.DataKeys[e.RowIndex]["HTZTZ"].ToString(), sysUser.Name);
this.ShowStateList();
}
catch (Exception ex)
{
WebAction.MessageBox(this, "add", ex.Message, null);
}
}
需要注意的:如果没使用datasource进行页面的绑定的话,删除或其他操作后,需要主动进行DataBind()的操作,以便删除后能够刷新显示为删除后的列表数据。