Shaksham Singh

Shaksham Singh

  • NA
  • 17
  • 6k

Find Repeater control in a function

Apr 30 2018 4:51 AM
Hello all, I am trying to bind my anchor tag from database value which is inside my repeater.
 
here is my repeater :
  1. <div class="popular_deals">  
  2. <div class="head">  
  3. <div class="popular_deals_heading">Popular Deals</div>  
  4. <div class="item">  
  5. <asp:Repeater ID="rptdealsbanner" runat="server" OnItemDataBound="rptdealsbanner_ItemDataBound">  
  6. <HeaderTemplate>  
  7. <ul id="autoplay" class="content-slider">  
  8. </HeaderTemplate>  
  9. <ItemTemplate>  
  10. <li id="mylist">  
  11. <a target="_blank" id="bannerAnchor">  
  12. <img src='<%#"PopularDeals/"+ Eval("BannerName") %>' alt='<%# Eval("BannerName") %>' />  
  13. </a>  
  14. <%-- <asp:ImageButton ID="imgBanner" runat="server" alt="Banner Image"></asp:ImageButton>  
  15. <asp:HiddenField ID="hdnBannerName" runat="server" Value='<%# Bind("BannerName") %>' />  
  16. <asp:HiddenField ID="lblurl" runat="server" Value='<%# Bind("BannerURL") %>'></asp:HiddenField>--%>  
  17. </li>  
  18. </ItemTemplate>  
  19. <FooterTemplate>  
  20. </ul>  
  21. </FooterTemplate>  
  22. </asp:Repeater>  
  23. </div>  
  24. </div>  
  25. </div>  
My code behind:
  1. private void GetDealsBanner()  
  2. {  
  3. try  
  4. {  
  5. BLPopularDeals objPD = new BLPopularDeals();  
  6. DataSet ds = objPD.GetDealsBanner(CountryFromCookies);  
  7. if (ds.Tables[0].Rows.Count > 0)  
  8. {  
  9. for(int i=0;i<ds.Tables[0].Rows.Count;i++)  
  10. {  
  11. HtmlAnchor a1 = (HtmlAnchor)rptdealsbanner.FindControl("mylist").FindControl("bannerAnchor"); //here i am getting null error ... how do i find my anchor tag and bind data ??  
  12. a1.HRef = ds.Tables[0].Rows[i]["BannerURL"].ToString() != null  
  13. ? ds.Tables[0].Rows[i]["BannerURL"].ToString()  
  14. "#";  
  15. }  
  16. rptdealsbanner.DataSource = ds.Tables[0];  
  17. rptdealsbanner.DataBind();  
  18. }  
  19. }  
  20. catch (Exception ex)  
  21. {  
  22. new TicketingError().Error(ex, "Default1.aspx---- GetDealsBanner()");  
  23. }  
  24. }  
Anybody help me out

Answers (1)