Is it possible to call the code command from c# to javascript function? -
this tricky me , don't know how solve one.. have 2 identical database table [table1,table2] want transfer database item database , delete data previous database avoid duplication.. used listbox1 , listbox2 after transfer data, next step want save changes.. have insert code on c# , i'm using on asp.net problem after transfer item listbox1 listbox2 click save changes button item move listbox2 go listbox1 run c# code -_- delay? think submit first before run c# code.. save code save same items :-/
that's why come idea of calling c# code function since javacript comes first .. if have better idea please share
here's tranfer item javascript code
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript"> $(function () { $("#left").bind("click", function () { var options = $("[id*=rightbox] option:selected"); (var = 0; < options.length; i++) { var opt = $(options[i]).clone(); $(options[i]).remove(); $("[id*=leftbox]").append(opt); } }); $("#right").bind("click", function () { var options = $("[id*=leftbox] option:selected"); (var = 0; < options.length; i++) { var opt = $(options[i]).clone(); $(options[i]).remove(); $("[id*=rightbox]").append(opt); } }); }); </script>
here's save c# code
(int = leftbox.items.count - 1; >= 0; i--) { //◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘ ◘add◘ ◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘ string[] splits = leftbox.items[i].tostring().split(new char[] { '-' }); string id_split = splits[0]; conn.close(); conn.open(); string str = "select * user_table_list id='" + id_split + "'"; sqlcommand com = new sqlcommand(str, conn); sqldatareader reader = com.executereader(); if (!reader.read()) { reader.close(); sqlcommand cmd = new sqlcommand("insert user_table_list (id, firstname,middlename,lastname,age,sex) values (@id, @fname, @mname, @lname,@age,@sex)", conn); cmd.parameters.add("@id", sqldbtype.nvarchar).value = splits[0].toupper(); cmd.parameters.add("@fname", sqldbtype.nvarchar).value = splits[1].toupper(); cmd.parameters.add("@mname", sqldbtype.nvarchar).value = splits[2].toupper(); cmd.parameters.add("@lname", sqldbtype.nvarchar).value = splits[3].toupper(); cmd.parameters.add("@age", sqldbtype.nvarchar).value = splits[4].toupper(); cmd.parameters.add("@sex", sqldbtype.nvarchar).value = splits[5].toupper(); cmd.executenonquery(); } conn.close(); //◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘ ◘delete◘ ◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘ conn.close(); conn.open(); string str8 = "select * user_table_list2 id='" + id_split + "'"; sqlcommand com8 = new sqlcommand(str8, conn); sqldatareader reader8 = com8.executereader(); if (reader8.read()) { string id = reader8["id"].tostring(); reader8.close(); string sql9 = "delete [user_table_list2] id='" + id + "'"; sqlcommand cmd9 = new sqlcommand(sql9, conn); cmd9.executenonquery(); conn.close(); } } }
i hope can me thank you
Comments
Post a Comment