Dynamically Add rows, cells, and controls to a table, and delete and read them for C # to read.

Source: Internet
Author: User

<Script language = JavaScript>
VaR I = 0;
VaR rowindex = 12;
Function addrow ()
{
Otr1 = table1.insertrow (rowindex );

Otd1 = otr1.insertcell (0 );
Otd2 = otr1.insertcell (0 );
Otd3 = otr1.insertcell (0 );
Otd4 = otr1.insertcell (0 );

Otd1.innerhtml = "<input type = text name = Name" + I + "> ";
Otd2.innerhtml = "<input type = text name = num" + I + "> ";
Otd3.innertext = "<input type = text name = post" + I + "> ";
Otd4.innertext = "<input type = text name = type" + I + "> ";
I ++;
Rowindex ++;
}

Function readvalue ()
{
VaR info = "";
VaR objinfo = Document. getelementsbyid ("txtinfo"); // txtinfo is a server control.
For (j = 0; j <I; j ++)
{
VaR temp = "";
VaR objname = Document. All ("name" + J );
VaR objnum = Document. All ("num" + J );
VaR objpost = Document. All ("Post" + J );
VaR objtype = Document. All ("type" + J );
Temp = temp + objname. Value + "\" + objnum. Value + "\" + objpost. Value + "\" + objtype. value;
Info = info + temp;
}
Objinfo. value = Info;
}

Function deleterow ()
{
Rowindex --;
I --;
Table1.deleterow (rowindex );
}

Used in C # code
String [] STR = textbox1.text. Split ("\\");
Extract the separated strings.

Note: you cannot set the visible of txtinfo to false. Otherwise, JavaScript cannot be read. For example, <type = hidden> C # cannot be read. My approach is: set the width and height of txtinfo to 0, and bordercolor to the background color.

Related Article

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.