none
How to sort listbox items and save this sorting in database RRS feed

  • Question



  • now this is the code in .aspx file
        
    <div>
                    <center><asp:DataList ID="DataList1" runat="server" RepeatColumns="5" CellPadding="4" CellSpacing="10"  OnItemCommand="DataList1_ItemCommand">
                    <ItemTemplate>
                        <table width="90%">
                            <tr>
                                <td>
                                   <asp:ImageButton ID="ImageButton1" CommandArgument='<%#Eval("D_NAME") %>' runat="server" Height="300px" Width="250px" ImageUrl='<%#Eval("D_IMAGE") %>' CommandName="viewdetail" /> <br /></td>
                                <td><br /></td>
                            </tr>
                        </table>
                    </ItemTemplate>
                    </asp:DataList></center>
                </div>


    and this s the code in .cs file
               
     SqlCommand cmd = new SqlCommand();
                SqlConnection con = new SqlConnection();
                SqlDataReader sdr;
                DataSet d = new DataSet();
               // string[] dno, dimage;
                int i = 0;
                protected void Page_Load(object sender, EventArgs e)
                {
                    if (Session["user_id"] == null)
                    {
                        Response.Redirect("login.aspx");
                    }
                    try
                    {
                        if (!IsPostBack)
                        {
                            con.ConnectionString = "Data Source=SHAHZAIB;Initial Catalog=CHILDREN_ISLAM;Integrated Security=True";
                            con.Open();
                            string q = "select * from DUAS inner join Selected_List on DUAS.DNO=Selected_List.DNO where Selected_List.U_ID='"+ Session["user_id"] + "'";
                            //cmd = new SqlCommand(q, con);
                            //sdr = cmd.ExecuteReader();
                            SqlDataAdapter sda = new SqlDataAdapter(q, con);
                            DataTable dt = new DataTable();
                            sda.Fill(dt);
                            DataList1.DataSource = dt;
                            DataList1.DataBind();
                            // dno[i] = sdr["DNO"].ToString();
                            //dimage[i] = sdr["D_IMAGE"].ToString();
                            //daudio[i] = sdr["D_AUDIO"].ToString();
        
                            //CheckBoxList2.DataValueField = "DNO";
                            ////CheckBoxList1.DataValueField = "D_IMAGE";
                            //CheckBoxList2.DataTextField = "D_IMAGE";
                            //// CheckBoxList1.DataValueField = "D_AUDIO";
                            ////DataTable dt = new DataTable();
                            ////sda.Fill(dt);
                            ////string[] a = { "a", "b", "c" };
                            //CheckBoxList2.DataSource = sdr;
                            //CheckBoxList2.DataBind();
                            i++;
        
                        }
        
                        con.Close();
                    }
                    catch (Exception ex)
                    {
        
                        Response.Write(ex.ToString());
                    }
        
                }
        
        
        
                protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
                {
                    string DNO = e.CommandArgument.ToString();
                    Response.Redirect("duacontainer.aspx?e=" + DNO);
        
        
        
        
                }


    what i simply want to do is to drag one of the listbox item which is being displayed and if i place it on another listbox it should be replaced with that and this sorting should be saved in database as soon as its replaced
    i know i can use jquery draggable or sortable but i don't know how to store it in database so that when user logs in again he get to see the sorting he did last time
    • Moved by CoolDadTx Friday, July 31, 2020 1:45 PM ASP.NET related
    Friday, July 31, 2020 10:52 AM

All replies

  • Hello,

    Here is the forum for ASP.NET questions https://forums.asp.net/


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, July 31, 2020 11:16 AM