Asp.net Repeater drag and drop to implement sorting and synchronize the sorting fields to the database

Source: Internet
Author: User

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 ){}}}}}}

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.