在Gridview中进行更新操作的LINQ查询 [英] LINQ Query For Update Operation in Gridview

查看:95
本文介绍了在Gridview中进行更新操作的LINQ查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Gridview中进行更新操作的LINQ查询
请帮助..

LINQ Query For Update Operation in Gridview
plz help..

推荐答案



没有用于更新GirdView的LINQ查询,而是您必须使用LINQ更新数据源并重新绑定GirView.

检查以下链接,以使用LINQ更新数据表,
在C#中使用LINQ更新数据表 [ ^ ]
如何使用linq进行批量更新 [
Hi,

There is no LINQ query for updating the GirdView, rather you have to update the Datasource using LINQ and rebind the GirView.

check below links, for updating the datatable using LINQ,
Update DataTable using LINQ in C#[^]
how to do bulk update using linq[^]

LINQ will update 1 column at a time, if you want to update muultiple columns, repeat the code as shown below.

objDataTable.AsEnumerable().ToList().ForEach(p => p.SetField<int>("COlumn1", 10));
objDataTable.AccectChanges();
objDataTable.AsEnumerable().ToList().ForEach(p => p.SetField<string>("COlumn2", "New Value"));
objDataTable.AccectChanges();

//as many columns you want to update.



如果您只想根据条件更新选定的行,请尝试以下操作.



if you want to update only selected rows based on the condition try as below.

objDataTable.AsEnumerable().Where(c => c.Fiels<int>("Coloumn1") == 10).ToList().ForEach(p => p.SetField<int>("COlumn1", 10));
objDataTable.AccectChanges();
objDataTable.AsEnumerable().Where(c => c.Fiels<int>("Coloumn1") == 10).ToList().ForEach(p => p.SetField<string>("COlumn2", "New Value"));
objDataTable.AccectChanges();

//as many columns you want to update.
//This will update the rows for which column1 = 10


的行
以后绑定网格视图



Later bind the gird view

GridView1.DataSource = objDataTable;
GridView1.DataBind();



希望对您有所帮助.



hope it helps.


这篇关于在Gridview中进行更新操作的LINQ查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆