页面:
<asp:DataList ID="dlTop" runat="server" OnItemDataBound="dlTop_ItemDataBound">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<div style="text-align: center; padding-top: 5px; padding-bottom: 5px">
<a class="a_title" href='<%= "ShowBBS.aspx?forum_id="%><%# Eval("forum_id") %>' target="_blank">
<asp:Label ID="lblTopTitle" runat="server" Text='<%# Eval("forum_header") %>'></asp:Label>
</a>
</div>
<div style="float: left; padding-left: 5px; width: 100px; text-align: left">
<asp:Label ID="lblContent" runat="server" CssClass="abstract" Text='<%# Eval("forum_content")%>'></asp:Label>
<a class="a_he" href='<%= "ShowBBS.aspx?forum_id="%><%# Eval("forum_id") %>' target="_blank">
[详细]</a>
</div>
</ItemTemplate>
</asp:DataList>代码:
protected void dlTop_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item )
{
Label lblContent = (Label)e.Item.FindControl("lblContent");
lblContent.Text = lblContent.Text.Length > 22 ? lblContent.Text.Substring(0, 22) + "..." : lblContent.Text;
}
}为什么标红的那行值不为true?调试看e.Item.ItemType的值为header,而ListItemType.Item的值为item
<asp:DataList ID="dlTop" runat="server" OnItemDataBound="dlTop_ItemDataBound">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<div style="text-align: center; padding-top: 5px; padding-bottom: 5px">
<a class="a_title" href='<%= "ShowBBS.aspx?forum_id="%><%# Eval("forum_id") %>' target="_blank">
<asp:Label ID="lblTopTitle" runat="server" Text='<%# Eval("forum_header") %>'></asp:Label>
</a>
</div>
<div style="float: left; padding-left: 5px; width: 100px; text-align: left">
<asp:Label ID="lblContent" runat="server" CssClass="abstract" Text='<%# Eval("forum_content")%>'></asp:Label>
<a class="a_he" href='<%= "ShowBBS.aspx?forum_id="%><%# Eval("forum_id") %>' target="_blank">
[详细]</a>
</div>
</ItemTemplate>
</asp:DataList>代码:
protected void dlTop_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item )
{
Label lblContent = (Label)e.Item.FindControl("lblContent");
lblContent.Text = lblContent.Text.Length > 22 ? lblContent.Text.Substring(0, 22) + "..." : lblContent.Text;
}
}为什么标红的那行值不为true?调试看e.Item.ItemType的值为header,而ListItemType.Item的值为item
=======>
你是第一次看到的吧?继续走就看到item了.