^ _ ^, Learn JavaScript, move up and down rows, use js to save the data to the XML file, and then read the XML on the server side and save it to the database.

Source: Internet
Author: User

// (Remember that this XML file cannot be saved on the client. You can put it in a hiddenfile)

Function createxmls ()
{
VaR rowsarray = Document. All ('tbllist'). Rows; // obtain all rows in the table.
VaR oxml = new activexobject ("Microsoft. xmldom"); // create an XML Object
Oxml = Document. createelement ("data"); // create a "data" element <DATA> </data>

For (VAR I = 1; I <rowsarray. length; I ++)
{
If (rowsarray [I]. cells [1] = NULL | rowsarray [I]. cells [3] = NULL | rowsarray [0]. cells [2] = NULL) break;
Oitem = oxml. appendchild (document. createelement ("item"); // create an item element and use it as a child node of data
Itemid = oitem. appendchild (document. createelement ("Itemid"); // create the Itemid element and use it as a subnode of the item
Itemname = oitem. appendchild (document. createelement ("itemname"); "); // create the itemname element and use it as a subnode of the item

Itemtype = oitem. appendchild (document. createelement ("itemtype"); // create the itemtype element and use it as a subnode of the item
Itemid. appendchild (document. createtextnode (rowsarray [I]. cells [2]. innertext); // create a text node and use it as a subnode of Itemid
Itemname. appendchild (document. createtextnode (rowsarray [I]. cells [3]. innertext ));
Itemtype. appendchild (document. createtextnode (rowsarray [I]. cells [1]. innertext ));
}

// Rowsarray [I]. cells [2]. innertext: the value of innertext in the third column of the current row.
VaR hidvalue = Document. getelementbyid ("ctl00_contentplaceholder1_hidxmlstring ");
Hidvalue. value = oxml. outerhtml;
}

// * Innerhtml,... difference

Innerhtml sets or obtains the HTML in the start and end tags of an object.
Outerhtml sets or obtains the HTML format of the object and its content
Innertext sets or obtains the text in the object's start and end labels.
Outertext setting (including tags) or obtaining (excluding tags) the text of an object
Innertext and outertext are the same when reading and obtaining data, but when you set them, outertext will replace them with tags to the target text.
Firefox does not support innertext, but textcontent can be used as an alternative.

// Test

<Div id = "Div"> <font color = "green"> <H2> This Is A Div! </H2> </font> </div>
<Input name = "innerhtml" value = "innerhtml" type = "button" onclick = "alert (div. innerhtml); "> // Result:"> <font color = "green"> <H2> This Is A Div! </H2> </font>


<Input name = "outerhtml" value = "outerhtml" type = "button" onclick = "alert (div. outerhtml); "> // result: <Div id =" Div "> <font color =" green "> <H2> This Is A Div! </H2> </font> </div>

<Input name = "innertext" value = "innertext" type = "button" onclick = "alert (Div. innertext);">
<Input name = "outertext" value = "outertext" type = "button" onclick = "alert (Div. outertext);">

*/

// The created XML

<DATA>

<Item>

<Itemid> 1 </Itemid>

<Itemname> FF </itemname>

<Itemtype> 1 </itemtype>

<Item>

 

<Item>

<Itemid> 1 </Itemid>

<Itemname> FF </itemname>

<Itemtype> 1 </itemtype>

<Item>

.......

</Data>

 

 

// Save the server-side read XML to the database:

Protected void savexmltodatabase ()

{

String xmlstring = This. hidxmlstring. value. Trim (); // retrieve XML from hiddenbutton
Xmldocument Doc = new xmldocument ();
Doc. loadxml (xmlstring); // load it into an XML file
Xmlnodelist rootlist = Doc. selectsinglenode ("data"). childnodes;
Dictionary promotion = New Dictionary ();
Bool flag = false;

Foreach (xmlnode xfnode in rootlist)
{
Xmlelement xe1 = (xmlelement) xfnode;
Xmlnodelist xitemlist = xe1.childnodes; // continue to obtain all the child nodes of the Xe subnode
Foreach (xmlnode xnnode in xitemlist)
{

Xmlelement Xe = (xmlelement) xnnode;

If (Xe. Name. tolower () = "Itemid ")
{
Promotion ["promo_rank"] = Xe. innertext;
}
If (Xe. Name. tolower () = "itemname ")
{
Promotion ["promo_name"] = Xe. innertext;
}
If (Xe. Name. tolower () = "itemtype ")
{
Promotion ["promo_type"] = Xe. innertext;
}
}
Flag = bllsales. addorupdatepromotionbyrank (promotion, enums. dataaccessmode. Update );
}

}

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.