0

I am using Visual Studio 2015 with framework 4.5 and with db as SQL SERVER.

I have one page that has values of the parent data:

Parent Data:

1

2

Child Data:

1

1.1

1.2

2

2.1

2.2

2.3

I want to display only child records in a list but I also have to give functionality to up and down the records inside the list box and save on the spot in db same as shown in list with ordering as well.

Please help me I don't have permission to use any third party js or any third party functionality as of now to do this feature.

I only have HTML as CSHTML , C# in backend code, SQL SERVER as DB and jquery with CSS3 only.

I got a list but mix data child records and display it in list box as well but don't know how to put that up down functionality please help me.

3 rules
  • 1,359
  • 3
  • 26
  • 54
  • SQL Server does not store data in any order. It is random. The SQL Server uses many threads when doing querying and storing so the data never is in any order. You must use Order By when querying to get sorted results. – jdweng Dec 01 '16 at 10:35
  • You need to show us the code that you tried, or else we cannot help. Please see https://stackoverflow.com/help/how-to-ask – Peter B Dec 01 '16 at 10:40
  • @PeterB No sir I know without any posting of code or demo it is very difficult to give an answer but I didn't try anything because I don't know how to do this things as jdweng said I got one idea that I can set one field i.e. orderby field in table so I can manipulate as per my need but still helpless cause how I can do up down things in ui side? – 3 rules Dec 01 '16 at 11:28
  • @jdweng thanks for the comments as per your comment I have got one idea that I can put one field i.e. OrderNo in table so I can manipulate it later as per my need but sir what about display those in ui side with up and down functionality I am still confuse!!! – 3 rules Dec 01 '16 at 11:29
  • I usually make a global variable index which contains the current index. The when the up button is press increase the index making sure it doesn't exceed the number of items in the list. For done button do the same except don't let index go negative. – jdweng Dec 01 '16 at 11:40
  • @jdweng yes sir It is a correct approach if I want it in client side but I also want to make changes in database as per user changes done in list on the spot or may be on save button and I think on save button is better than server call on change but still I am confuse how can I do that in ui side! – 3 rules Dec 01 '16 at 11:55
  • To change database you need to do an UPDATE. The UPDATE requires a WHERE that specifies which line(s) to change. It does not use an Index row number in a table. – jdweng Dec 01 '16 at 12:04
  • @jdweng yes correct I understand how to do changes in database now but how do I show it in ui side with up and down key can you please show me any code or something using css or jquery so I can later read one by one all the list values and update the database on save button. – 3 rules Dec 01 '16 at 12:10
  • See msdn for Update : https://msdn.microsoft.com/en-us/library/ms177523.aspx You would need a for loop that enumerates the items in the ListBox. The data (like an ID #) in the row would be used in the WHERE. – jdweng Dec 01 '16 at 12:31
  • @jdweng Really appreciated sir help me a lot thanks I will try those things that we have discussed and come back with the answer I hope. – 3 rules Dec 01 '16 at 12:43

1 Answers1

1

I think you can use jquery's best concept html control moving and you can get orders by reading all that one by one as unique id in "items" just like this code.

My suggestion is to give OrderBy field in database table so you just have to change the order number rather than chaging whole row up side down and visa versa.

Mahavirsinh Padhiyar
  • 1,299
  • 11
  • 33
  • Yes I can use this let me check I can read all the id's or not! – 3 rules Dec 19 '16 at 09:44
  • 1
    Yes you can read if you have set those id inside the div or html control that you have used read [this](http://stackoverflow.com/questions/11544072/jquery-each-through-divs-inside-another-div) – Mahavirsinh Padhiyar Dec 19 '16 at 09:46