我有一箇中繼器,只有存在時才顯示綁定字段值。讀了this post我決定通過在我的轉發器中使用一個字面值並使用OnItemDatabound觸發器來填充我的字面值,但我的字面值似乎無法從後面的c#代碼訪問,我不明白爲什麼!空字面問題
繼承人的aspx頁面
<asp:Repeater runat="server" ID="rpt_villaresults" OnItemDataBound="checkForChildren">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
//.................MORE CODE HERE......................
<div class="sleeps"><h4>To Sleep</h4><h5><%#Eval("sleeps")%> <asp:Literal ID="sleepsChildrenLit" runat="server" /> </h5></div>
//.............MORE CODE HERE........................
背後
public void checkForChildren(object sender, RepeaterItemEventArgs e)
{
Literal childLit = e.Item.FindControl("sleepsChildrenLit") as Literal;
//this is null at runtime
String str = e.Item.DataItem.ToString();
if (e.Item.DataItem != null)
{
if (Regex.IsMatch(str, "[^0-9]"))
{
if (Convert.ToInt32(str) > 0)
{
childLit.Text = " + " + str;
}
}
}
}
英雄所見略同;) – 2008-12-23 11:21:21