2011-06-22 5 views
0

オブジェクト参照がオブジェクトのインスタンスに設定されていません。コードバインドファイルには、クリックイベントのコードが含まれています。エラー:オブジェクト参照がオブジェクトのインスタンスに設定されておらず、リストビューでfindcontrolを使用してラベル値を取得しています

protected void viewProfileLinkButton_Click(object sender, EventArgs e) 
     { 
      String emailID = ((Label)ListView1.FindControl("profileTitleLabel")).Text; 
      Response.Redirect("profilePage.aspx?e=" + emailID); 
     } 

私のaspxページでは、このようなものです:

default1.aspx: 

<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" 
        onselectedindexchanged="ListView1_SelectedIndexChanged"> 
      <LayoutTemplate> 
       <div ID="itemPlaceholderContainer" runat="server" style=""> 
        <span runat="server" id="itemPlaceholder" /> 
       </div> 
       <div style=" text-align:right; margin-right:100px; width:750px;"> 
        <asp:DataPager ID="DataPager1" runat="server" PageSize="2"> 
         <Fields> 
          <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
           ShowNextPageButton="False" ShowPreviousPageButton="False" /> 
          <asp:NumericPagerField /> 
          <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" 
           ShowNextPageButton="False" ShowPreviousPageButton="False" /> 
         </Fields> 
        </asp:DataPager> 
       </div> 
      </LayoutTemplate> 
      <AlternatingItemTemplate> 
      <hr style=" float:left; width:552px; margin-left:17px;"/> 
      <div class="center_title_bar" style="text-align:left;"> 
        <asp:Label ID="nameLabel" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"first_name") %>'></asp:Label> 
     </div> 
     <div class="profile_box_big"> 
      <div class="top_profile_box_big"></div> 
      <div class="center_profile_box_big">   
       <div class="profile_img_big"> 
       &nbsp;<asp:Image ID="profileImage" runat="server" Height="160px" Width="150px" /> 
       </div> 
        <div class="details_big_box"> 
         <div class="specifications"> 
          <asp:Label ID="profileTitleLabel" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"email_id") %>' 
           ForeColor="#388977"></asp:Label><br /> 

         <asp:LinkButton ID="viewProfileLinkButton" runat="server">View Profile</asp:LinkButton> 
        </div>       
      </div> 
      <div class="bottom_profile_box_big"></div> 
      </div>       
     </div> 
      </AlternatingItemTemplate> 
      <EditItemTemplate/> 
      <EmptyDataTemplate> 

      </EmptyDataTemplate> 
      <InsertItemTemplate/> 
      <ItemTemplate> 
      <br /> 
       <div class="center_title_bar" style="text-align:left;"> 
        <asp:Label ID="nameLabel" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"first_name") %>'></asp:Label> 
     </div> 
     <div class="profile_box_big"> 
      <div class="top_profile_box_big"></div> 
      <div class="center_profile_box_big">   

        <div class="details_big_box"> 
         <div class="specifications"> 
          <asp:Label ID="profileTitleLabel" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"email_id") %>' 
           ForeColor="#388977"></asp:Label><br /> 

         </div> 
         <asp:LinkButton ID="viewProfileLinkButton" runat="server" OnClick="viewProfileLinkButton_Click">View Profile</asp:LinkButton> 
        </div>       
      </div> 
      <div class="bottom_profile_box_big"></div> 
      </div>       
     </div> 
      </ItemTemplate> 
      <SelectedItemTemplate/> 
     </asp:ListView> 

私を助けてください、ありがとう.....

答えて

0

FindControl機能ですので、ターゲットコントロールを見つけることができませんでしたListViewに直接含まれていません。

1

あなたのHTMLは質問で面白くなってしまったので、ListView1がどこにあるのかわかりません。私はそれがListViewだと仮定するのは安全だと思います。その場合は、ListView自体ではなくListViewItem内にあるので、Labelをそのように見つけることはできません。聞くのは素晴らしいことだ

ListView1.Items[0].FindControl("profileTitleLabel");のようなものは、あなたが

+0

をやるべき事は、それは完全に罰金働いて、どうもありがとうございましたされて..... –

+0

...ので、通常はアスカーは答えをupvoteし、最良の答えだろう – BritishDeveloper

関連する問題