首页 新闻 会员 周边 捐助

Asp.net获取ListView中LayoutTemplate中的一个很奇怪的问题?

0
悬赏园豆:100 [已关闭问题]

前台代码:

  <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;
        }

cswgylive的主页 cswgylive | 初学一级 | 园豆:5
提问于:2009-06-13 10:49
< >
分享
其他回答(2)
0

Cells是指单元格吧,就是td

斯克迪亚 | 园豆:4124 (老鸟四级) | 2009-06-13 10:55
0

XD!

.Rows[0].Cells 第1行的CELL是单元格,但从代码里边缺怀疑你的结果,明明是6个TD,怎么会是5?

蠕虫 | 园豆:305 (菜鸟二级) | 2009-06-13 11:10
0

把第六个TD中的runat="server"属性去掉

风海迷沙 | 园豆:4453 (老鸟四级) | 2009-06-13 11:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册