Asp.net background to get JS table data

Source: Internet
Author: User

Will float Ajax

Many people on the Forum are looking for the data in the JS table in the background, so they put the previous method here.

Front-end:

 <% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. CS "inherits =" _ default "%> </P> <p> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> </P> <p> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead runat = "server"> <br/> <title> Asp.net: obtain data from the front-end JS table </title> <br/> <style type = "text/CSS"> <! -- <Br/>. dis-ime <br/>{< br/> ime-mode: disabled; <br/>}</P> <p> --> <br/> </style> <br/> </pead> <br/> <body> <br/> <Form ID = "form1" runat = "server"> <br/> <p> use a client to add and save tables </p> <br/> <p> <br /> the master node is submitted to the server, process the information in the table and assign the value to hidden <br/> to mqtheone. Here, I set that only numbers can be entered in the last column, for more information, see <br/> </P> <br/> <div> </P> <p> <Table id = "tab1"> <br/> <tr> <br/> <TH> name </Th> <br/> <TH> content </Th> <br/> <TH> value </Th> <br/> <TH> </ Th> <br/> </tr> <br/> <TD> <input type = "text"/> </TD> <br/> <TD> <input type = "text"/> </TD> <br/> <TD> <input type = "text" class = "dis-ime" onkeypress = "Return check (Event) "/> </TD> <br/> </tr> <br/> </table> <br/> <input type =" button "style =" margin-left: 400px "mce_style =" margin-left: 400px "value =" add information "id =" btnaddinfo "/> <br/> <asp: button id = "button1" runat = "server" text = "Submit" onclientcl Ick = "initdata ();" <br/> onclick = "button#click"/> <br/> <asp: hiddenfield id = "hiddenfield1" <br/> runat = "server"/> </P> <p> </div> <br/> </form> <br/> </body> <br/> <SCRIPT type = "text/JavaScript"> <! -- <Br/> var $ = function () {return document. getelementbyid (arguments [0]) ;}; </P> <p> var check = function (e) {<br/> Return e. keycode <= 57 & E. keycode >=48 <br/>}</P> <p >$ ("btnaddinfo "). onclick = function () {<br/> var TB = $ ("tab1"); // to mqtheone: here you can use the ID of the table on the server, or find the first table on the page <br/> var ROW = TB. insertrow (TB. rows. length); <br/> for (VAR I = 0; I <2; I ++) {<br/> var TD = row. insertcell (I); <br/> TD. innerhtml = "<input type = 'text'/>"; <br/>}< br/> row. insertcell (row. cells. length ). innerhtml = "<input type = 'text' class = 'dis-ime 'onkeypress = 'Return check (event)'/>"; // The style sheet disables the input method, filter and then numeric characters, and paste is not disabled yet, <br/> row. insertcell (row. cells. length ). innerhtml = "<input type = 'button 'onclick = 'Return remove (this) 'value = 'delete'/> "; <br/>}< br/> var remove = function (OBJ) {<br/> var TR = obj. parentnode. parentnode; <br/> tr. parentnode. removechild (TR); <br/>}</P> <p> var initdata = function () {<br/> var TB = $("tab1 "); <br/> var DATA = []; <br/> for (VAR I = 1; I <TB. rows. length; I ++) {<br/> If (TB. rows [I]. cells [0]. firstchild. value. length> 0 & TB. rows [I]. cells [1]. firstchild. value. length> 0) {// Add the items whose values are not empty in the two text boxes to the array. Assume that only the data in the first two columns cannot be blank <br/> data. push (TB. rows [I]. cells [0]. firstchild. value); <br/> data. push (TB. rows [I]. cells [1]. firstchild. value); <br/> data. push (TB. rows [I]. cells [2]. firstchild. value); <br/>}// else {here, you can give a message indicating that the data is not complete and whether to submit the data, otherwise return false }< br/>}< br/>$ ("hiddenfield1 "). value = data. join ("'"); // concatenate the array into a string using this uncommon character <br/> return true; <br/> }; <br/> // you can add a method to determine whether the hidden is empty. If it is not empty, retrieve the data for traversal, add to table <br/> // --> </SCRIPT> <br/> </ptml> <br/>

Background retrieval:

Using system; <br/> using system. configuration; <br/> using system. data; <br/> using system. LINQ; <br/> using system. web; <br/> using system. web. security; <br/> using system. web. ui; <br/> using system. web. UI. htmlcontrols; <br/> using system. web. UI. webcontrols; <br/> using system. web. UI. webcontrols. webparts; <br/> using system. XML. LINQ; </P> <p> Public partial class _ default: system. web. UI. page <br/> {<br/> pro Tected void page_load (Object sender, eventargs e) <br/>{</P> <p >}< br/> protected void button#click (Object sender, eventargs E) <br/>{< br/> If (hiddenfield1.value! = "") <Br/>{< br/> string [] datas = hiddenfield1.value. split ('''); <br/> int I = 0; <br/> system. collections. hashtable TB = new system. collections. hashtable (); <br/> datatable dt = new datatable (); // put the retrieved data into the datatable <br/> DT. columns. add ("name", typeof (string); <br/> DT. columns. add ("content", typeof (string); <br/> DT. columns. add ("value", typeof (INT); <br/> while (I <datas. length) <br/> {<br/> string str1 = datas [I]; // this way, the data is retrieved. <br/> string str2 = datas [I + 1]; <br/> string str3 = datas [I + 2]; <br/> int V = 0; <br/> Int. tryparse (str3, out V); <br/> datarow DR = DT. newrow (); <br/> Dr ["name"] = str1; <br/> Dr ["content"] = str2; <br/> Dr ["value"] = V; <br/> DT. rows. add (DR); <br/> I + = 3; <br/>}< br/> response. write ("the number of data rows is" + dt. rows. count); <br/>}< br/>

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.