想拥有多行.net表

时间:2012-09-11 13:36:35

标签: c# .net html-table

我想知道为什么.Net表行被添加到同一行而不是多行?

具体问题在于此代码:

this.table.Rows.AddAt(0,labels);
this.table.Rows.AddAt(1,fields);
this.table.Rows.AddAt(2,submits);

表是一个WebControls.Table
标签,字段和提交是TableRows
这些都包括TableCells。

但是当我在浏览器中查看它时,它表示为< tr> “所有的行和列”

< / tr>

然后两个空

< tr> < / tr> < tr> < / tr>

标记..?

所以它添加了单元格和行的所有内容,它甚至添加了三行但是由于某种原因它将所有信息放在第一行

< tr> 标签

任何想法我做错了什么?

<table border="0">
        <tr>
            <td><span>please enter the title of the interaction here</span></td><td><span>please enter the description of the interaction here</span></td><td><span>please select the impact level of the interaction here</span></td><td><span>please select the urgency level of the interaction here</span></td><td><span>please enter the contact of the interaction here</span></td><td><input name="ctl00$PlaceHolderMain$ctl00$ctl06" type="text" value="one" /></td><td><input name="ctl00$PlaceHolderMain$ctl00$ctl07" type="text" value="two" /></td><td><select name="ctl00$PlaceHolderMain$ctl00$ctl08">
                <option selected="selected" value="1">Low</option>
                <option value="2">Medium</option>
                <option value="3">High</option>

            </select></td><td><select name="ctl00$PlaceHolderMain$ctl00$ctl09">
                <option selected="selected" value="1">Low</option>
                <option value="2">Medium</option>
                <option value="3">High</option>

            </select></td><td><input name="ctl00$PlaceHolderMain$ctl00$ctl10" type="text" value="con" /></td><td rowspan="3"><input type="submit" name="ctl00$PlaceHolderMain$ctl00$ctl11" value="Create Interaction" /></td><td rowspan="2"><span>No interactions created yet</span></td>
        </tr><tr>

        </tr><tr>

        </tr>
    </table>

1 个答案:

答案 0 :(得分:1)

您可以通过传递单元容器来尝试使用此代码

/adding first row
TableRow row1 = new TableRow();

//adding first cell
TableCell cell1 = new TableCell();

//adding label
Label text1 = new Label();
text1.Text = "Just test";

cell1.Controls.Add(text1);
row1.Controls.Add(cell1);
table1.Controls.Add(row1);