前台代码:
<LayoutTemplate>
<table id="table" runat="server">
<tr class="button" id="test" runat="server">
<td>
<asp:LinkButton ID="lbtnUserName" runat="server" CommandArgument="UserName" CommandName="Sort">姓名</asp:LinkButton>
<img alt="按姓名排序" src="~/images/icon-n.gif" runat="server" border="0" id="imgUserName" />
</td>
<td>
<asp:LinkButton ID="lbtnPhone" runat="server" CommandArgument="Phone" CommandName="Sort">电话</asp:LinkButton>
<img alt="按电话号码排序" src="~/images/icon-n.gif" runat="server" border="0" id="imgPhone" />
</td>
<td>
<asp:LinkButton ID="lbtnQQ" runat="server" CommandArgument="QQ" CommandName="Sort">QQ</asp:LinkButton>
<img alt="按QQ号码排序" src="~/images/icon-n.gif" runat="server" border="0" id="imgQQ" />
</td>
<td>
<asp:LinkButton ID="lbtnBrithDate" runat="server" CommandArgument="BrithDate" CommandName="Sort">出身日期</asp:LinkButton>
<img alt="按出身日期排序" src="~/images/icon-n.gif" runat="server" border="0" id="imgBrithDate" />
</td>
<td>
<asp:LinkButton ID="lbtnRole" runat="server" CommandArgument="RoleID" CommandName="Sort">角色</asp:LinkButton>
<img alt="按角色排序" src="~/images/icon-n.gif" runat="server" border="0" id="imgRoleID" />
</td>
<td runat="server" id="op">
操作
</td>
</tr>
<tr runat="server" id="occupy">
</tr>
</table>
</LayoutTemplate>
后台代码:
int cellcount = (lv.FindControl("table") as HtmlTable).Rows[0].Cells.Count;
//明明只有2个控件为什么cellcount 是5??
string controls = ((lv.FindControl("table") as HtmlTable).Rows[0].Cells[0].FindControl("lbtnUserName") as Control).GetType().Name;
for (int n = 0; n < cellcount; n++)
{
//string str = (lv.FindControl("table") as HtmlTable).Rows[0].Cells[n].Controls.Count.ToString();
string str = (((lv.FindControl("table") as HtmlTable).Rows[0] as HtmlTableRow).Cells[n] as HtmlTableCell).Controls.Count.ToString();
//((lv.FindControl("table") as HtmlTable).Rows[0].Cells[n].Controls[0] as Literal).Visible = false;
}
Cells是指单元格吧,就是
XD!
.Rows[0].Cells 第1行的CELL是单元格,但从代码里边缺怀疑你的结果,明明是6个TD,怎么会是5?
把第六个TD中的runat="server"属性去掉