0

我有一个带有删除按钮的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);
}

有什么建议么?

一切顺利,麻木

4

1 回答 1

1

将这些行放在if (result == DialogResult.Yes)块中:

populateOrderLines(intOrderID); // This repopulates the gv so why is it blank?
populateOrderTotals(intOrderID);
于 2012-10-22T15:54:22.347 回答