Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello everyone,

I used jquery to sort the grid, its working well, but I am getting a problem in saving it.
How can I save it according to priorities?
There is a column named priority in grid, I want to save the new priorities after sorting in the database, for example like if my grid is something like this, I will post the code too.
ID    Title    Priority
1       abc       1
2       xyz       2 
3       pqr       3


Now if I sorted the grid and made the order of

2
3
1


Then how can I save it in the database so that the record with "ID 2" gets priority 1 then record with priority 3 gets priority 2 and so on for other records...

I want to do this on save button click.
I trid foreach
(gridview row in gridview.rows)
{
string abc = gridview1.rows[0].cells[2].tostring();
}

I'm getting 1 everytime in the string.
please help.
Posted
Updated 18-Mar-11 12:12pm
v3
Comments
Wendelius 18-Mar-11 15:58pm    
Edit: Added pre tags
Dalek Dave 18-Mar-11 18:13pm    
Edited for Grammar and Readability.

The sorting is being done on the client side so of course when you get to the server it is not going to be sorted (remember how databinding works?). You will need to use some JavaScript to post the data, in the correct order. Using a AJAX this is not difficult. Alternatively, you would need to set some field, most likely a hidden field, with the order and read it when saving on the server.
 
Share this answer
 
Comments
Dalek Dave 18-Mar-11 18:13pm    
Good Answer.
From your description It's look like you are doing sorting directly on Grid itself.Why don't you perform all your Grid Operations(Sort,Edit,Delete) on dataset and finally bind that resultset to Grid for fresh view.Update whatever the priorities you want on Dataset itself and bind it to Grid.You can also add new record..I mean with new Priority to dataset and finally save dataset itself to Database not by looping your Grid.

Hope it helps you!!
 
Share this answer
 
Comments
Dalek Dave 18-Mar-11 18:14pm    
Good Call.

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