Click here to Skip to main content
11,581,982 members (75,085 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
LINQ Query For Update Operation in Gridview
plz help..
Posted 28-Sep-12 18:13pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 355
1 Sergey Alexandrovich Kryukov 220
2 Andy Lanng 110
3 virusstorm 109
4 Kornfeld Eliyahu Peter 90
0 OriginalGriff 1,358
1 Sergey Alexandrovich Kryukov 970
2 Abhinav S 671
3 F-ES Sitecore 505
4 Suvendu Shekhar Giri 448


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100