jQuery排序网格保存 [英] Jquery sorted grid saving

查看:101
本文介绍了jQuery排序网格保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我使用jquery对网格进行了排序,其工作正常,但是在保存时遇到了问题.
如何根据优先级保存它?
在网格中有一个名为优先级的列,我想在数据库中排序后保存新的优先级,例如,如果我的网格是这样的话,我也将发布代码.

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



然后如何将其保存在数据库中,以使具有"ID 2"的记录具有优先级1,然后具有优先级3的记录具有优先级2,依此类推,对于其他记录...

我要在单击保存按钮时执行此操作.
我尝试过foreach



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();
}


我每次在字符串中都得到1.
请帮忙.


I''m getting 1 everytime in the string.
please help.

推荐答案

排序是在客户端进行的,因此,当您进入服务器时,当然不会对其进行排序(记住数据绑定的工作方式?).您将需要使用一些JavaScript以正确的顺序发布数据.使用AJAX并不难.另外,您需要设置一些字段,最有可能是隐藏字段,并带有顺序,并在保存到服务器上时将其读取.
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.


从您的描述中看起来直接在Grid本身上进行排序为什么不对数据集执行所有Grid操作(Sort,Edit,Delete),最后将结果集绑定到Grid以获取新鲜的视图.更新想要在Dataset本身上的优先级并将其绑定您还可以添加新记录..我的意思是对数据集使用新的优先级,并最终将数据集本身保存到数据库中,而不用循环网格.

希望对您有帮助!
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!!


这篇关于jQuery排序网格保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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