c# - checkbox value not inserting in database -
whenever checkbox in dialog box checked , after clicking button doesn't save data database save 'n' checkbox checked saves 'n' how solve problem. want save 'y' database if checkbox checked.
html:-this html section in checkbox declared
<form id="form1" runat="server"> <div id="dialog"> <label>first</label> <asp:checkbox id="checkbox1" runat="server" /> <label>second</label> <asp:checkbox id="checkbox2" runat="server" /> <label>third</label> <asp:checkbox id="checkbox3" runat="server" /> </div> <asp:button id="button1" runat="server" text="button" onclick="button2_click" /> </form> jquery:-here jquery script.dialogbox checkbox <script type="text/javascript"> $(document).ready(function () { $("#dialog").dialog({ buttons: { ok: function () { $("[id*=button1]").click(); }, close: function () { $(this).dialog('close'); } } }); }); </script> code behind:- c# code behind file inserting data in database using ado , sql protected void button2_click(object sender, eventargs e) { clientscript.registerstartupscript(page.gettype(), "key", "alert('button clicked')", true); string first = checkbox1.checked ? "y" : "n"; string second = checkbox2.checked ? "y" : "n"; string third = checkbox3.checked ? "y" : "n"; string cs = configurationmanager.connectionstrings["dum01connectionstring"].connectionstring; using (sqlconnection scon = new sqlconnection(cs)) { using (sqlcommand cmd = new sqlcommand("insert checkbox (first,second,third) values(@first,@second,@third)")) { cmd.connection = scon; cmd.parameters.addwithvalue("@first", first); cmd.parameters.addwithvalue("@second", second); cmd.parameters.addwithvalue("@third", third); scon.open(); cmd.executenonquery(); scon.close(); } } } saves 'n' database if checkbox checked saves 'n' database how solve
i debugged code on side, didn't find issue in code. getting expected value y
whenever checked checkbox.
it seems issue might coming somewhere else.
see attached screenshot of debugging.
in above screenshot, checked first checkbox
, got it's value y
in debugging part.
suggestion:
try taking code new fresh page , implement part of functionality. idea, issue coming somewhere else.
hope helps, let me know if face other issues related this.
update
since using dialog box
, have @ below link reference. might you
Comments
Post a Comment