如何擷取Footer中的子控制項

來源:互聯網
上載者:User
真的許久沒更新blog了,不是無所事事,確實是因為急著趕快完成工作

事實上這個問題出現在我為Repeater控制項添加分頁功能時。情況是這樣的:                            <footertemplate>
                                <tr>
                                    <td colspan="9">
                                        <asp:panel ID="PageRow" Runat="server" EnableViewState="True">
                                            共
                                            <asp:label ID="PageRowsCount" Runat="server"></asp:label>條記錄,當前第
                                            <asp:label ID="PageIndex" Runat="server"></asp:label>頁/
                                            <asp:label ID="PageCount" Runat="server"></asp:label>頁
                                            
                                        </asp:panel>
                                    </td>
                                </tr>
                            </footertemplate>

老規矩,多餘的代碼就不說了

這個Panel出於兩方面考慮,一方面作為容器以獲得裡面的幾個控制項,另一方面使用它的div套用樣式。
但是奇怪的是無論如何在Repeater裡FindControl都沒法得到它。

別著急,Controls實際上是Repeater的資料行集,


Footer總是在最後一個,So...

 

                Panel pagepanel = (Panel)(typecontracts.Controls[typecontracts.Controls.Count-1].FindControl("PageRow"));

 

                Label pagerowscount = (Label)pagepanel.FindControl("PageRowsCount");
                int pagecount = list.RowsCount % pagesize > 0 ? list.RowsCount/pagesize + 1 : list.RowsCount/pagesize;
                ((Label)pagepanel.FindControl("PageCount")).Text = pagecount.ToString();
                ((Label)pagepanel.FindControl("PageIndex")).Text = ( list.PageIndex+1 ).ToString();
                for ( int i=0; i< pagecount; i++ )
                {
                    System.Web.UI.WebControls.HyperLink link = new HyperLink();
                    link.Text = (i+1).ToString();
                    link.NavigateUrl="index.aspx?tid=" + contracttype.TypeID + "&sid=" + DContractStates.SelectedValue + "&pid=" + (i*pagesize+1).ToString();
                    pagepanel.Controls.Add( link );
                }
                pagerowscount.Text = list.RowsCount.ToString();

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.