Click here to Skip to main content
15,560,045 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Hi,

I am having a gridview in that I am having select check box. While selecting the rows and clicking the Update button I am selecting the rows which are selected in the gridview through linq. In this selected linq query I want to get the two column values(SlNO,RefNO) as a result set. How to get this one through linq. Here is my linq code for selecting the selected value from the grid.

SQL
var result = from GridViewRow msgRow in grdPrice.Rows
                    where ((CheckBox)msgRow.FindControl("chkSelect")).Checked
                    select grdPrice.Rows[msgRow.RowIndex];



Thanks
Posted

1 solution

You can use an Anonymous Types properties to do your task.Please check the below sample.

C#
var result = (from GridViewRow msgRow in grdPrice.Rows
                    where ((CheckBox)msgRow.FindControl("chkSelect")).Checked
                    select new {
                                 SlNO=YourSInoValue,
                                 RefNO=YourRefNOValue,
                               }).ToList();
 
Share this answer
 
v5
Comments
Member 7946563 1-Feb-14 1:56am    
How to save this list as arraylist.
Sampath Lokuge 1-Feb-14 1:59am    
You can save it by using 'foreach loop'.Just loop through the list and save it in your tables.
You can access your list values by using result.SlNO and result.RefNO etc...
Member 7946563 1-Feb-14 2:01am    
Without for loop any other way.
Sampath Lokuge 1-Feb-14 2:02am    
Nope,You cannot.B'cos this is the list.If it's a single value then you can.What is your problem ?
Member 7946563 1-Feb-14 2:07am    
I want to select only the slno from that linq query like 1,2,3,4,5 and I want to send it to database to update the values.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900