Hallo, ich versuche, Elemente in Datentabelle aus Gridview hinzufügen, wenn die Bedingung erfüllt ist.Mehrere Datensätze in Datentabelle
Die Bedingung ist ReceivedQuantity < OrderedQuantity
Das Problem ist, wenn ich mehr als ein Element, das den Zustand Datentabelle nur ein Element unter erfüllt.
-Code
List<string> PurchaseReturnsItems = new List<string>();
foreach (GridViewRow row in griddelpur.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chkRow = (row.Cells[0].FindControl("chkSel") as CheckBox);
if (chkRow.Checked)
{
string PurchaseOrderDetailID = row.Cells[1].Text;
string itemcode = row.Cells[2].Text;
string itemname = row.Cells[3].Text;
string UOM = row.Cells[4].Text;
string OrderedQuantity = row.Cells[5].Text;
string ReceivedQuantity = (row.Cells[6].FindControl("txtReceivedQty") as TextBox).Text;
string Comments = (row.Cells[7].FindControl("txtComments") as TextBox).Text;
string ItemID = row.Cells[8].Text;
if (Convert.ToInt32(ReceivedQuantity) < Convert.ToInt32(OrderedQuantity))
{
PurchaseReturnsItems.Add(ItemID);
DataTable tbl = new DataTable();
tbl.Clear();
tbl.Columns.Add("ItemID");
tbl.Columns.Add("ItemCode");
tbl.Columns.Add("UOM");
tbl.Columns.Add("ItemName");
tbl.Columns.Add("ReturnedQuantity");
DataRow dr = tbl.NewRow();
dr["ItemID"] = ItemID;
dr["ItemCode"] = itemcode;
dr["UOM"] = UOM;
dr["ItemName"] = itemname;
dr["ReturnedQuantity"] = Convert.ToInt32(OrderedQuantity) - Convert.ToInt32(ReceivedQuantity);
tbl.Rows.Add(dr);
gridpurahsereturn.DataSource = tbl;
gridpurahsereturn.DataBind();
}
}
}
}