首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

为什么在repeater中取不到一些服务端控件,这是为什么呢?该怎么解决

2012-01-01 
为什么在repeater中取不到一些服务端控件,这是为什么呢?aspx里是这样子写的,asp:Panel IDpanelList ru

为什么在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里边去找

热点排行