Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
hi,
i used javascript(on double click) for moving items from first listbox to second listbox..
and want to second listbox items store in database
but i am fail to do this..
hard work and hard search i ask you here.
so please help me...i need the solution for my site..

i have two tables
1) star_master
and
2) profile_star


two listboxes
1) lst_leftstar
2) lst_rightstar

lst_leftstar is display(load) from star_aster table
and lst_rightstar will be blank..

select(doubleclcik on) items for move items lst_leftstar to lst_rightstar
and lst_rightstar items will be store in database....
i tried too much..but my coding is failed here...
coz when i click on submit button "lst_rightstar" show me 0 items in loop.
my javascript coding is :=

XML
<script type="text/javascript">        /* star  */
        function lst_left_star_DblClicked() {
            var left_lst = document.getElementById("<%=lst_leftstar.ClientID%>");
            var right_lst = document.getElementById("<%=lst_rightstar.ClientID%>");

            for (var i = 0; i < left_lst.length; i++) {
                if (left_lst.options[i].selected == true) {
                    right_lst.options[right_lst.length] =
            new Option(left_lst.options[i].text,
            left_lst.options[i].value);
                    left_lst.options[i] = null;
                    i = i - 1;
                }
            }
            return;
        }
    </script>

<script type="text/javascript">
        function lst_right_star_DblClicked() {
            var left_lst = document.getElementById("<%=lst_leftstar.ClientID%>");
            var right_lst = document.getElementById("<%=lst_rightstar.ClientID%>");

            for (var i = 0; i < right_lst.length; i++) {
                if (right_lst.options[i].selected == true) {
                    left_lst.options[left_lst.length] = new Option(right_lst.options[i].text, right_lst.options[i].value);
                    right_lst.options[i] = null;
                    i = i - 1;
                }
            }
            return;
        }
    </script>

<asp:ListBox ID="lst_leftstar" onDblClick="lst_left_star_DblClicked();" runat="server"
                                Height="100px" Width="180px"></asp:ListBox>

<asp:ListBox ID="lst_rightstar" onDblClick="lst_right_star_DblClicked();" runat="server"
                                Height="100px" Width="180px"></asp:ListBox>


please tell me how can i stored my listbox items in database.
i tried but not success...
Posted

1 solution

Hi Manish,

I too faced the same issue, for same similar scenario ;-)
My scenario is

Having one autocomplete text box and one list box.
When user selects value from auto complete text box, that item should added in list box.
I did it in Javascript but when I tried to save it in DB I could not, because client side newly added items in listbox is not reflected in server side :-(

For that what I did is, Added each items in Hidden value with delimeter(~) whenever item is selected in autocomplete text box.
In server side I split the hidden values (eg: Item1~Item2~Item3) and binded in database as required.

You could also do the same if you want.

Hope this helps you a bit.

Regards,
RK
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900