为什么在repeater中取不到一些服务端控件,这是为什么呢?
aspx里是这样子写的,
<asp:Panel ID="panelList" runat="server">
<asp:AccessDataSource ID="AcesDS" runat="server" DataFile="~/App_Data/rprssz#@017.mdb"
SelectCommand="SELECT top 10 [Title] FROM [Article]"></asp:AccessDataSource>
<asp:Repeater ID="rpList" runat="server" DataSourceID="AcesDS">
<HeaderTemplate>
<div style="width:100%;height:30px; background-color:#aaa">
<asp:Label id="channelName" runat="server"></asp:Label>
</div>
</HeaderTemplate>
<ItemTemplate>
<li style="font-size:10pt;line-height:20px;text-decoration:none;
word-break:break-all;text-overflow:ellipsis;
overflow:hidden; list-style-type:circle;
padding-left:5px;">
<a href="#" ><%#Eval("Title") %></a>
</li>
<br />
</ItemTemplate>
</asp:Repeater>
</asp:Panel>
上面加红的部份在服务端无法取得,为什么呢?
取不到这样一个值this.channelName.Text
真是搞不懂,请高手帮帮忙吧。。。
------解决方案--------------------if(e.ItemType==ListItemType.HeaderItem)
{
Label channelName=e.Item.FindControl("channelName") as Label;
}
------解决方案--------------------.aspx
<asp:Repeater ID="rpList" runat="server" OnItemDataBound="rpListItemDataBound" ></asp:Repeater>
.cs
void rpListItemDataBound(object sender,RepeaterItemEventArgs e)
{
if(e.ItemType==ListItemType.HeaderItem)
{
Label channelName=e.Item.FindControl("channelName") as Label;
}
}
------解决方案--------------------很明显,空间再header里边,就要到header里边去找