日期:2014-05-18 浏览次数:20619 次
function CreateTable(ds) { var maxRow =8; var maxCol = 3; var aaa="test"; var strTbody ="<table <tbody>"; strTbody+="<tr>"; for(var j = 0; j < maxCol; j++) { strTbody+="<td><input id=\"txt"+i+"\" type =\"text\" value ="+aaa+" /></td>"; } strTbody+="</tr>"; strTbody+="</tbody></table>"; var obj = document.getElementById("tableDiv"); obj.innerHTML = strTbody; }
function addRow() { //添加一行 var newTr = tableone.insertRow(); //添加3列 var newTd0 = newTr.insertCell(); var newTd1 = newTr.insertCell(); var newTd2 = newTr.insertCell(); //设置列内容和属性 newTd0.className = "LtableCopy"; newTd0.height = "25"; newTd0.align = "center"; newTd0.innerHTML = "<input type='text' name='pickname' />"; newTd1.className = "LtableCopy"; newTd1.height = "25"; newTd1.align = "center"; newTd1.innerHTML = "<input type='text' name='pickrelationship'/>"; newTd2.className = "LtableCopy"; newTd2.height = "25"; newTd2.align = "center"; newTd2.innerHTML = "<input type='text' name='picknumber' />"; }
------解决方案--------------------
Table t1 = new Table();
TableRow[] trList = new TableRow[dtProtal.Rows.Count];
for (int i = 0; i < dtProtal.Rows.Count; i++)
{
//添加第一列CheckBox
CheckBox[] cbList = new CheckBox[dtProtal.Rows.Count];
cbList[i] = new CheckBox();
cbList[i].Text = dtProtal.Rows[i][2].ToString();
cbList[i].ID = "cbID" + i;
if (Convert.ToBoolean(dtProtal.Rows[i][3]))
{
cbList[i].Checked = true;
}
TableCell cellName = new TableCell();
cellName.Controls.Add(cbList[i]);
//添加第二列HtmlSelect
HtmlSelect[] selectList = new HtmlSelect[dtProtal.Rows.Count];
selectList[i] = new HtmlSelect();
selectList[i].ID = "select" + i;
selectList[i].Value = dtProtal.Rows[i][1].ToString();
selectList[i].Attributes.Add("style", "width:80px;");
selectList[i].Attributes.Add("runat", "server");
ListItem itemL = new ListItem();
itemL.Text = "左列";
itemL.Value = "0";
ListItem itemM = new ListItem();
itemM.Text = "中列";
itemM.Value = "1";
ListItem itemR = new ListItem();
itemR.Text = "右列";
itemR.Value = "2";
if (Convert.ToChar(dtProtal.Rows[i][1]) == '0')
itemL.Selected = true;
if (Convert.ToChar(dtProtal.Rows[i][1]) == '1')
itemM.Selected = true;
if (Convert.ToChar(dtProtal.Rows[i][1]) == '2')
itemR.Selected = true;
if (cbSystem.Checked)
selectList[i].Items.Add(itemR);
else
{
selectList[i].Items.Add(i