当前位置:编程学习 > C#/ASP.NET >>

我正在使用vs2008,使用了listview控件,在模板里添加了一个HyperLink,想用findcontrol找到这个控件,为什么找不到,提示没有HyperLink3这个控件

  <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" 
         GroupItemCount="4" >
         <AlternatingItemTemplate>
             <td runat="server" style="background-color:#FFF8DC; width:80px;height:120px">
                 <asp:HyperLink ID="HyperLink1" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' NavigateUrl='<%# Eval("SureUrl") %>'/>
           </td>
           <td style="width:80px;height:120px">
                 <asp:HyperLink ID="HyperLink2" runat="server" Text='<%# Eval("Introduce") %>' NavigateUrl='<%# Eval("SureUrl") %>'/>
                 
             </td>
         </AlternatingItemTemplate>
         <LayoutTemplate>
             <table runat="server">
                 <tr runat="server">
                     <td runat="server">
                         <table ID="groupPlaceholderContainer" runat="server" border="0" 
                             style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
                             <tr ID="groupPlaceholder" runat="server">
                             </tr>
                         </table>
                     </td>
                 </tr>
                 <tr runat="server">
                     <td runat="server" 
                         
                         style="text-align: center;background-color: #CCCCCC; font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
                     </td>
                 </tr>
             </table>
         </LayoutTemplate>
        
             <EmptyItemTemplate>
                 <td runat="server" />
                 </EmptyItemTemplate>
        
             <InsertItemTemplate>
                 <td runat="server" style="">
                     ImageUrl:
                     <asp:TextBox ID="ImageUrlTextBox" runat="server" 
                         Text='<%# Bind("ImageUrl") %>' />
                     <br />
                     Introduce:
                     <asp:TextBox ID="IntroduceTextBox" runat="server" 
                         Text='<%# Bind("Introduce") %>' />
                     <br />
                     <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="插入" />
                     <br />
                     <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="清除" />
                     <br />
                 </td>
             </InsertItemTemplate>
             <SelectedItemTemplate>
                 <td runat="server" 
                     style="background-color: #008A8C; font-weight: bold;color: #FFFFFF;">
                     ImageUrl:
                     <asp:Label ID="ImageUrlLabel" runat="server" Text='<%# Eval("ImageUrl") %>' />
                     <br />
                     Introduce:
                     <asp:Label ID="IntroduceLabel" runat="server" Text='<%# Eval("Introduce") %>' />
                     <br />
                 </td>
             </SelectedItemTemplate>
             <GroupTemplate>
                 <tr ID="itemPlaceholderContainer" runat="server">
                     <td ID="itemPlaceholder" runat="server">
                     </td>
                 </tr>
             </GroupTemplate>
             <EmptyDataTemplate>
                 <table runat="server" 
                     style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
                     <tr>
                         <td>
                             未返回数据。</td>
                     </tr>
                 </table>
             </EmptyDataTemplate>
             <EditItemTemplate>
                 <td runat="server" style="background-color: #008A8C; color: #FFFFFF;">
                     ImageUrl:
                     <asp:TextBox ID="ImageUrlTextBox" runat="server" 
                         Text='<%# Bind("ImageUrl") %>' />
                     <br />
                     Introduce:
                     <asp:TextBox ID="IntroduceTextBox" runat="server" 
                         Text='<%# Bind("Introduce") %>' />
                     <br />
                     <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="更新" />
                     <br />
                     <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="取消" />
                     <br />
                 </td>
             </EditItemTemplate>
             <ItemTemplate>
                 <td runat="server" style="background-color: #DCDCDC; color: #000000; width:80px;height:120px">
                     <asp:HyperLink ID="HyperLink3" runat="server" 
                         ImageUrl='<%# Eval("ImageUrl") %>'  />
                   </td>
                   <td style="width:80px;height:120px">
                     <asp:HyperLink ID="HyperLink4" runat="server" Text='<%# Eval("Introduce") %>' %>'/>
                     <br />
                    </td>
                     
             </ItemTemplate>
     </asp:ListView> --------------------编程问答-------------------- 在具体的数据行上调用findcontrol --------------------编程问答-------------------- 怎么调用呀
我是这样做的HyperLink Hl=(HyperLink)this.listview.findcontrol(HyperLink3) --------------------编程问答-------------------- 我在帖子《e.item.cells[] 怎么用》中对FindControl有一个简单解释。 --------------------编程问答-------------------- 在帖子《GridView1获取模板列很诡异的异常,高手都来帮我看看...。。。。。。愁~》的12楼,我解释了如何不用去管容器,直接从一个模板中的LinkButton查找其它模板中的控件,可以参考。 --------------------编程问答-------------------- 我用的是ListView和GridView不太一样啊 --------------------编程问答--------------------
引用 5 楼 ilovejava123 的回复:
我用的是ListView和GridView不太一样啊


看内容了吗?
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,