Click here to Skip to main content
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 Sergey Alexandrovich Kryukov 329
1 Nirav Prabtani 274
2 OriginalGriff 239
3 _Amy 165
4 Richard MacCutchan 145
0 OriginalGriff 7,744
1 Sergey Alexandrovich Kryukov 6,956
2 Maciej Los 3,994
3 Peter Leow 3,708
4 CHill60 2,742


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2014
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