Asp.net Repeater drag and drop to implement sorting and synchronize the sorting fields to the database
There is a unit table in the database table that contains fields such as ID, Name, and Order. Now there is a background management function that allows you to set the display sequence of these units in certain statistical tables, so we thought of using the drag-and-drop method to make the operation easier.
An example animation is made using the GifCam software. The effect is shown in:
As a result, we found that jquery. ui providesSortableFunction, which can be used for sorting. The Repeater control is used from the units bound to the database in the interface. The following describes the main steps:
1.Jquery-1.7.2.min.jsAndJquery-ui.min.jsPlease click to download, address: http://download.csdn.net/detail/taomanman/9315373
2. The TestDemo. aspx code is as follows:
<Script src = ".../Scripts/jquery-1.7.2.min.js"> </script> <script src = ".../Scripts/jquery-ui.min.js"> </script>
The TestDemo. cs code is as follows. The specific database operation class obtains data based on the actual situation, which is not detailed here.
Public partial class TestDemo: System. Web. UI. Page {public static GGJ_DC_DataCenterBaseInfoBLL bll = new GGJ_DC_DataCenterBaseInfoBLL (); protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {BindData ();}}////// Bind a ministry/organization ///Public void BindData () {string where = ""; string orderby = "F_Order ASC"; DataTable dt = bll. getData (where, orderby); this. rpt. dataSource = dt; this. rpt. dataBind ();}}
3. The update. aspx and update. aspx. cs codes of the $. ajax Method Request page are as follows:
Public partial class update: System. Web. UI. Page {public static GGJ_DC_DataCenterBaseInfoBLL bll = new GGJ_DC_DataCenterBaseInfoBLL (); protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {string order = Request ["order"]. toString (); string depId = Request ["id"]. toString (); UpdateOrder (depId, order );}}////// Re-update the order /////////Public void UpdateOrder (string deptId, string order) {string [] deptIds = deptId. split (','); string [] orders = order. split (','); for (int I = 0; I <deptIds. length; I ++) {for (int j = 0; j <orders. length; j ++) {if (I = j) {string SQL = "update GGJ_DC_DataCenterBaseInfo set F_Order =" + orders [j] + "where F_DataCenterID = '" + deptIds [I] + "'"; DataTable dt = CommonClass. querySQL. getDataTable (SQL); if (dt. rows. count> 0 ){}}}}}}