在下面的代碼中,我有網格視圖,其中有6列,其中有1 dropdown
和5 textbox
。我的目標是刪除特定的行。我試過但我可以無法刪除特定的行。刪除網格視圖中的特定行
protected void gvInvoice_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
DataTable dtCurrentTable = new DataTable();
int RowIndex = e.RowIndex;
dtCurrentTable = (DataTable)ViewState["CurrentTable"];
dtCurrentTable.Rows.RemoveAt(e.RowIndex);
SetPreviousData1(dtCurrentTable);
}
private void SetPreviousData1(DataTable dtCurrentTable)
{
int rowIndex = 0;
if (dtCurrentTable != null)
{
DataTable dt = dtCurrentTable;
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
Label lblProductID = (Label)gvInvoice.Rows[rowIndex].Cells[1].FindControl("lblProductID_i");
DropDownList txtProductName = (DropDownList)gvInvoice.Rows[rowIndex].Cells[2].FindControl("EditableddlProductName");
TextBox txtQuantity = (TextBox)gvInvoice.Rows[rowIndex].Cells[3].FindControl("txtQuantity");
TextBox txtProductPrices = (TextBox)gvInvoice.Rows[rowIndex].Cells[4].FindControl("lblProductPrices");
TextBox txtProfitPrice = (TextBox)gvInvoice.Rows[rowIndex].Cells[5].FindControl("txtProfitPrice");
TextBox txtTaxCalculation = (TextBox)gvInvoice.Rows[rowIndex].Cells[6].FindControl("txtTaxCalculation");
TextBox txtTotaPrice = (TextBox)gvInvoice.Rows[rowIndex].Cells[7].FindControl("txtTotaPrice");
lblProductID.Text = dt.Rows[i]["Column1"].ToString();
txtProductName.Text = dt.Rows[i]["Column2"].ToString();
txtQuantity.Text = dt.Rows[i]["Column3"].ToString();
txtProductPrices.Text = dt.Rows[i]["Column4"].ToString();
txtProfitPrice.Text = dt.Rows[i]["Column5"].ToString();
txtTaxCalculation.Text = dt.Rows[i]["Column6"].ToString();
txtTotaPrice.Text = dt.Rows[i]["Column7"].ToString();
rowIndex++;
}
}
}
}
謝謝它運作良好 – Thiyagu