The reason is that in the statement
grdPt02Documents.DataSource = resultRow ;
the
resultRow
is out of scope as it is declared within the scope of
foreach
loop.
Further, the statement
foreach (string list in DocList)
{
var resultRow = (from Data in (dtDocuments.AsEnumerable())
where Data.Field<string>("DocumentId") ==list.ToString()
select Data);
}
will give the rows corresponding to the last string in
DocList
as it will replace any resultRow found earlier.
The
list
is already a
string
and list.ToString() is redundant.
I think the following code can be used for the purpose stated in the question
string[] docIds = DocumentList.Split(',');
var resultTable = (dtDocuments.AsEnumerable().Where (d => docIds
.Any (i => d.Field<string>("DocumentId")
.Equals(i.Trim(), StringComparison.InvariantCulture)))
.Select (d =>d )).CopyToDataTable();