I have DataViewone that is populated with a list of files from a database table. I want to iterate through a DataView to see if there are any files of a certain type, and if so, do something with this record and then delete it from the DataView.
I encoded it as follows, but something is missing there - I can iterate over the object and then delete the object from it, as this will affect the iterator.
Any suggestions?
DataView dv = new DataView();
dv = ds.Tables[3].DefaultView;
dlFiles.DataSource = dv;
dlFiles.DataBind();
for (int j = 0; j < dv.ToTable().Rows.Count; j++) {
if (dv.ToTable().Rows[j]["FilePath"].ToString().ToLower().Contains(".pdf")) {
//do something with this record and remove it from the dataview
}
}
As a note, dlFilesused DataListto display items in DataView. Deleted files are displayed differently, and therefore should not be referenced when repeating through DataList.
source
share