这里我试图删除数据行Table.I想要删除单击索引中的值等于0的行。我尝试但删除所有数据Table.Solution?
protected void btnTest_Click(object sender, EventArgs e)
{
DataTable dtCurrentTable = (DataTable)ViewState["Markici"];
decimal noofcount = Convert.ToInt32(count);
var clickedRow = ((Button)sender).NamingContainer as GridViewRow;
var clickedIndex = clickedRow.RowIndex;
decimal old = dtCurrentTable.Rows[clickedIndex].Field<decimal>("Kolicina");
//int oldValue = int.Parse(old); // in case that you don't know
decimal newValue = old - 1; // just an example
dtCurrentTable.Rows[clickedIndex].SetField("Kolicina", newValue.ToString());
////Here i'm trying to delete row of clicked button.
if (old == 0)
{
for (int i = 0; i <= dtCurrentTable.Rows.Count; i++)
{
dtCurrentTable.Rows[clickedIndex].Delete();
dtCurrentTable.AcceptChanges();
GridView2.DataSource = dtCurrentTable;
GridView2.DataBind();
}
}
//dtCurrentTable.Rows[clickedIndex]["Kolicina"] == "0";
GridView2.DataSource = dtCurrentTable;
GridView2.DataBind();
}
答案 0 :(得分:0)
为什么你甚至会循环?
if (old == 0)
{
dtCurrentTable.Rows[clickedIndex].Delete();
dtCurrentTable.AcceptChanges();
}