public void dg_delete(Object sender,DataGridCommandEventArgs e)
{
if (DataGrid1.EditItemIndex == (int)e.Item.ItemIndex)
{
Response.Write("编辑状态无法删除!");
}
else
{
String deleteCmd = "DELETE from jobs where
job_id=@jobid";
SqlCommand com = new SqlCommand(deleteCmd, con);
com.Parameters.Add(new SqlParameter("@jobid", SqlDbType.SmallInt, 2));
Response.Write((int)e.Item.ItemIndex);
com.Parameters["@jobid"].Value = DataGrid1.DataKeys[(int)e.Item.ItemIndex];
com.Connection.Open();
try
{
com.ExecuteNonQuery();
Response.Write("已删除");
}
catch (SqlException exc)
{
Response.Write("无法删除");
Response.Write(exc.Message);
}
com.Connection.Close();
BindGrid();
}
}
这是删除的一部分代码获取行的索引来操作一行,不知道是你说的那个不``