从数据视图中删除记录
我有一个 DataView,其中填充了数据库表中的文件列表。我想遍历 DataView 以查看是否存在特定类型的文件,如果有,则对该记录执行某些操作,然后将其从 DataView 中删除。
我已将其编码如下,但缺少一些东西 - 我可以迭代一个对象,然后从中删除一个对象,因为这会影响迭代器。
有什么建议吗?
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
}
}
请注意,dlFiles
是一个DataList
,用于显示DataView
中的项目。删除的文件显示方式不同,因此在迭代 DataList
时不应引用。
I have a DataView
which has been populated with a list of files from a database table. I want to iterate through the DataView to see if there are any files there of a particular type, and if so, do something with that record, and then remove it from the DataView.
I've coded this as follows, but there's something missing - I can iterate over an object and then remove an object from it, since that 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, dlFiles
is a DataList
used to display the the items in the DataView
. The files removed are displayed differently, and so should not be referenced when iterating through the DataList
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们可以这样做,
We can do like this,
好吧,使用一个新的对象,例如数据表,将新数据复制到该数据表,并绑定您的控件。
Well,use a new object such as datatable,copy the new data to this datatable,and bind your control.