我使用Repeater
生成表格,我需要將<td>
設置爲runat=server
以設置它的可見性。如何找到runat = server的HTML標籤到中繼器?
我試圖用FindControl
方法找到ItemDataBound
事件,但它不起作用。 熱我可以做到這一點?
我使用Repeater
生成表格,我需要將<td>
設置爲runat=server
以設置它的可見性。如何找到runat = server的HTML標籤到中繼器?
我試圖用FindControl
方法找到ItemDataBound
事件,但它不起作用。 熱我可以做到這一點?
這應該做的伎倆。首先,創建一個方法來捕獲中繼器的OnDataItemBound事件。
protected void MyRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
// Use FindControl, but start from the context of the RepeaterItem.
//
HtmlTableCell cell = e.item.FindControl("CellID") as HtmlTableCell;
if (cell != null)
{
// Do what you gotta do.
}
}
可以明確連線事件了中繼器上的標記。
<asp:Repeater ID="MyRepeater" runat="server" OnItemDataBound="MyRepeater_ItemDataBound">
</asp:Repeater>
'FindControl'返回'null'這不起作用 – davioooh
你是否逐字複製我的代碼?請發佈您的代碼。 –
您可以添加一些相關的代碼的問題? – Erwin