我有一个带删除按钮的gridview。我添加了一个消息框,其中包含'你确定'是/否。单击“是”时,数据行将被删除,但如果单击“否”,则gridview数据将消失。
以下是删除按钮的代码:
private void gvOrderLines_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int intOrderID = 0;
if (e.RowIndex < 0 || e.ColumnIndex != gvOrderLines.Columns["deleteBtn"].Index) return;
Int32 orderLineID = (Int32)gvOrderLines[1, e.RowIndex].Value;
DialogResult result = MessageBox.Show("Do you want to delete this item? ","Delete Item",MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
using (SqlConnection conn = new SqlConnection(connection))
{
SqlCommand comm;
comm = new SqlCommand("del_OrderLine", conn);
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add(new SqlParameter("@orderLineID", SqlDbType.Int));
comm.Parameters["@orderLineID"].Value = orderLineID;
comm.Parameters.Add("@ReturnValue", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
try
{
conn.Open();
comm.ExecuteNonQuery();
intOrderID = (int)comm.Parameters["@ReturnValue"].Value;
}
catch
{
//tba
}
finally
{
comm.Dispose();
conn.Close();
}
}
}
populateOrderLines(intOrderID); // This repopulates the gv so why is it blank?
populateOrderTotals(intOrderID);
}
有什么建议吗?
一切顺利, 麻木
答案 0 :(得分:1)
将这些行放在if (result == DialogResult.Yes)
块中:
populateOrderLines(intOrderID); // This repopulates the gv so why is it blank?
populateOrderTotals(intOrderID);