ASP. NET implementation pop-up box stores the data selected by the check box to the database (1), asp.net Database

Source: Internet
Author: User

ASP. NET implementation pop-up box stores the data selected by the check box to the database (1), asp.net Database

ASP. NET implementation pop-up box stores the data selected by the check box to the database by page. This problem takes several steps

1. Save the data selected by the check box after the real page is displayed.

2. upload the data saved in the pop-up box to the parent page.

3. display data on the parent page.

4. Click Save to save the information to the database.

First, save the data selected by the check box after the real page is displayed.

The idea is very simple, that is, the real page is first, and then when you click the next page, scan all the data that click the check box on this page and save it to a variable array. The following is the main code:

ASP code:

<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "ZCXDWLInfo. aspx. cs" Inherits = "WEB. DDGL. ZCXDWLInfo" %> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 

JS Code:

Var SaveCheck = new Array (); var SaveBig = 0; function pagingClick (text, index) {var pageSize = parseInt ($ ('# pageSize '). val (); // page size var pageIndex = parseInt ($ ('# pageindex '). val (); // var pageCount = parseInt ($ ('# pageCount') on the current page '). val (); // the total number of pages var recordCount = parseInt ($ ('# recordCount '). val (); // The total number of records if ("Previous Page" = text) {// click the previous page button if (pageIndex> 1) {// query and display the data getData (pageSize, pageIndex-1 ); $ ('# Pageindex '). val (pageIndex-1); // update the current page // alert ($ ('# lblpage '). text (); $ ('# lblpage '). text ('col' + recordCount + 'records, current' + (pageIndex-1) + '/' + pageCount + ', each page '+ pageSize + 'record');} else if ("next page" = text) {// click the next page button if (pageIndex <pageCount) {// query and display the data getData (pageSize, pageIndex + 1); $ ('# pageIndex '). val (pageIndex + 1); // update the current page $ ('# lblpage '). text ('col' + recordCount + 'records, current number' + (pa GeIndex + 1) + '/' + pageCount + ', each page' + pageSize + 'record ');} else if ("jump" = text) {// click the jump button var skinIndex =$ ('# current-Index '). trim (); // get the page number to jump to if (skinIndex! = PageIndex & skinIndex> = 1 & skinIndex <= pageCount) {// query and display the data getData (pageSize, skinIndex); $ ('# pageindex '). val (skinIndex); // update the current page $ ('# lblpage '). text ('col' + recordCount + 'records, current' + skinIndex + '/' + pageCount + ', each page' + pageSize + 'record ');} else {$ ('# current-Index '). val (''). focus (); return ;}} else {// click the home page and end page buttons // query and display the data getData (pageSize, parseInt (index )); $ ('# pageindex '). val (parseInt (in Dex); // update the current page $ ('# lblpage '). text ('col' + recordCount + 'records, current number' + parseInt (index) + '/' + pageCount + ', each page '+ pageSize + 'record ');}} // ================================================ ===================================================== ========================================================== ================================================ ====================================== display paging controls ============== ========================================================== function pagingShow (pageS Ize, pageIndex) {var intJBID = $ ('# hidJBID '). val (); // hide the control DLSCode if (intJBID = "null") {intJBID = "";} // =========================== number of customer information items, and output the pagination button to the interface =====================================$. ajax ({type: "get", // transfer type get url :".. /DDGL/handler/QueryZCXDCount. ashx? JBID = "+ intJBID, // The returned data is successfully parsed, and success: function (ZCXDCount) {var recordCount = parseInt (ZCXDCount) is displayed ); // total number of records $ ("# insert "). contents ("div "). remove (); // if (recordCount> 0) {// calculate the total number of pages based on the total number of records and the number of data entries displayed per page. var pageCount = (recordCount % pageSize = 0 )? ParseInt (recordCount/pageSize): parseInt (recordCount/pageSize) + 1; $ ('# pageCount '). val (pageCount); // assign the total number of pages to the hidden controls on the Interface $ ('# recordCount '). val (recordCount); // assign the total number of records to the hidden controls on the Interface // function _ getLink (text, index) {return J. formatString ('<a class = "button-white" href = "javascript: pagingClick (\'' + text +' \ ',' + index + '); "> <span> {0} </span> </a> ', text, index);} var html = []; html. push ('<div Class = "pager-bar"> '); html. push (J. formatString ('<div id = "lblPage" class = "msg"> {0} records in total, current number {1}/{2 }, {3} records per page </div> ', recordCount, pageIndex, pageCount, pageSize); html. push (_ getLink ('homepage ', 1); html. push (_ getLink ('preview', pageIndex-1); html. push (_ getLink ('Next pageIndex + 1); html. push (_ getLink ('page', pageCount); html. push (''); html. push ('th <input id = "current-index" onkeydown = "J. enterSubmit (even T, Pager. Jump); "class =" input-small "style =" text-align: center; "type =" text "value =" '+ (pageIndex> 0? PageIndex: '') + '"/> page'); html. push (''); html. push ('<a class = "button-white" href = "javascript: pagingClick (\ 'jump \',\'\'); "> <span> jump </span> </a> '); html. push ('</div>'); $ ("# insert "). append (html. join ('') ;}}, // failed to return data. error: function (XmlHttpRequest, textStatus, errorThrown) {alert (XmlHttpRequest. responseText );},});} // ========================================================== click the search button RESPONSE event ============================ ================================== Function search_Click () {var pagesize = 50; // page size var pageIndex = 1; // current page // assign the data to the hidden control on the page // $ ('# hidJBID '). val (intJBID); $ ('# pageSize '). val (pagesize); // page size $ ('# pageindex '). val (pageIndex); // the current page // display pagingShow (pagesize, pageIndex); // query and bind the data getData (pagesize, pageIndex); return false ;} // ================================================ ================================================= ========================================================== ======================================================== ==== Query part information based on page size and page number, and display the data in the table on the Interface =================================== =================== function getData (pageSize, pageIndex) {var intJBID = $ ('# hidjbid '). val (); // level ID if (intJBID = "null") {intJBID = "";} // ========================== query the part ID based on the level ID ======================== ===========================$. ajax ({type: "get", url :".. /DDGL/handler/QueryZ CXDAllInfo. ashx? JBID = "+ intJBID +" & pageSize = "+ pageSize +" & pageIndex = "+ pageIndex, // If the returned data is successful, the returned json data is parsed and success is displayed: function (strJson) {var obj = eval (strJson); // eval calculate the JavaScript string, run the script code and check the data returned by the background. // load the obtained data to the table dynamically $ ("# mainTable tr "). eq (1 ). removeClass ("contentDisplay"); // remove the style of the template row $ ("# mainTable tr "). eq (1 ). nextAll (). remove (); // Delete the tr of the title row. This refers to deleting the second tr. // You can traverse the obtained json data in sequence and dynamically load the data to the table. for (va) R I = 0; I <obj. length; I ++) {var row = $ ("# content "). the clone (); // clone () method generates a copy of the selected element, including the child node, text, and attributes. Row. find ("# LJBM "). text (obj [I]. LJBM); row. find ("# hidLJID "). val (obj [I]. ID); row. find ("# LJMC "). text (obj [I]. MC); row. find ("# hidDJ "). text (obj [I]. DJ); // $ ("# txtSL "). live ("onblur", function () {// $ ("# Money "). val () = $ ("# txtSL "). val () * $ ("# hidDJ "). val () //}); // details. When you click, pass the parameter and call the Detail_Click method // row. find ("# Detail "). bind ("click", {strDivisionID: obj [I]. strDivisionID, strEvaluaterCode: obj [I]. strEvaluaterCode}, Detail_Click); row. find ("# ckWLXZ") // row.css ("display", "inline"); row. appendTo ("# mainTable"); // Add to mainTable} $ ("# mainTable tr "). eq (1 ). addClass ("contentDisplay"); // Add the css style of the template column // transcode the color of the row $ ('table. data-table tr: even '). addClass ('even') ;}, // The error code returned when an error occurs. The error message "error: function (XmlHttpRequest, textStatus, errorThrown) {alert (XmlHttpRequest. responseText) ;}}) ;}// save and select the data function SaveCheckInfo () {var LJBM = document. getElementsByName ("LJBM"); var CheckInfo = document. getElementsByName ("ckWLXZ"); var LJID = document. getElementsByName ("hidLJID"); var SL = document. getElementsByName ("txtSL"); var Money = document. getElementsByName ("Money"); var LJMC = document. getElementsByName ("LJMC"); var DJ = document. getElementsByName ("hidDJ"); for (var I = 1; I <CheckInfo. length; I ++) {if (CheckInfo [I]. checked = true) {// '{"name": "cxh", "sex": "man"}' var strLJBM = LJBM [I]. innerHTML var strLJID = LJID [I]. value; var strSL = SL [I]. value; var strLJMC = LJMC [I]. innerHTML; var strMoney = Money [I]. innerHTML; var strDJ = DJ [I]. innerHTML; switch (I + 1) {case 2: SaveCheck [SaveBig] = '[{"LJBM": "' + strLJBM + '", "SL ": "'+ strSL +'", "Money": "'+ strMoney +'", "LJID": "'+ strLJID +'", "LJMC ": "'+ strLJMC +'", "DJ": "'+ strDJ +'", "DJBH": "-", "GSF": "-", "GLF ": "-"} 'break; // case CheckInfo. length: // SaveCheck [SaveBig] = '{"LJBM": "' + strLJBM + '", "SL": "' + strSL + '", "Money ": "'+ strMoney +'", "LJID": "'+ strLJID +'", "LJMC": "'+ strLJMC +'", "DJ ": "'+ strDJ +'", "DJBH": "-", "GSF": "-", "GLF": "-"}] '// break; default: saveCheck [SaveBig] = '{"LJBM": "' + strLJBM + '", "SL": "' + strSL + '", "Money ": "'+ strMoney +'", "LJID": "'+ strLJID +'", "LJMC": "'+ strLJMC +'", "DJ ": "'+ strDJ +'", "DJBH": "-", "GSF": "-", "GLF": "-"} 'break;} SaveBig ++; saveCheck [SaveBig] = "]" ;}}/ * place an order normally * // return all the stored data to the page */function getSelected () {SaveCheckInfo () window. returnValue = SaveCheck; window. close () ;}// calculate the amount function Money () {var SL = document. getElementsByName ("txtSL"); var DJ = document. getElementsByName ("hidDJ"); var TotalMoeny = 0; var Money = document. getElementsByName ("Money"); for (var I = 1; I <SL. length; I ++) {Money [I]. innerHTML = SL [I]. value * DJ [I]. innerHTML TotalMoeny = parseFloat (TotalMoeny) + parseFloat (Money [I]. innerHTML) // if (TotalMoeny> )}}

:




Summary:

In fact, this function selects the real paging and check box to save data. JS provides a zero-time cache (an array variable), which is integrated with the three technologies. These three functions can also be used separately.



In the aspnet background, we dynamically Add the checkbox to the panel, and click Save on the page to save the selected checkbox value to the database?

Click execute in the event: all controls in the loop panel. If it is checkbox, check whether it is selected. If yes, access the database to save it.

How can I insert the checkbox selected value to the database in aspnet?

Direct. value

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.