我有一个中继器,只有存在时才显示绑定字段值。读了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