Need to access a HyperlinkControl in Radgrid itemdatabound.

4 posts, 0 answers
  1. shahid Aleem
    shahid Aleem avatar
    32 posts
    Member since:
    Jan 2010

    Posted 04 Feb 2010 Link to this post

    In my Source Code file i have a Hyperlink control... Which i want to access and give the url from code behind. I did using the following method but it is giving me error.
    Please help me... Its very urgent.

    Its throwing an exception.
     
     <telerik:GridTemplateColumn HeaderText="Visit No." UniqueName="VisitNo" DefaultInsertValue=""
                                  
                                <ItemTemplate> 
                                    <asp:HyperLink ID="lblVisitNo" runat="server" Text='<%#Bind("SiteVisitNo") %>' ></asp:HyperLink> 
                                </ItemTemplate> 
                            </telerik:GridTemplateClumn>


     protected void gvRenewal_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
        { 
            HyperLink lblVisitNo = (HyperLink)e.Item.FindControl("lblVisitNo"); 
            int SiteID = int.Parse(Request.QueryString["SID"]); 
            lblVisitNo.NavigateUrl = "~/Pages/Sites/Management_Sites/Renewal_SiteVisits.aspx?SID=" + SiteID; 
       
  2. Mark Galbreath
    Mark Galbreath avatar
    171 posts
    Member since:
    Jul 2009

    Posted 04 Feb 2010 Link to this post

    What's the exception being thrown and the stack trace?

    Cheers!
    Mark
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. shahid Aleem
    shahid Aleem avatar
    32 posts
    Member since:
    Jan 2010

    Posted 05 Feb 2010 Link to this post

    Hello Mark Galbreath
    thanks for replying.

    its object reference not set to an instance of an object.
    at this line.
     lblVisitNo.NavigateUrl = "~/Pages/Sites/Management_Sites/Renewal_SiteVisits.aspx?SID=" + SiteID; 
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 Feb 2010 Link to this post

    Hello Shahid,

    You would have to differentiate between the various rows in the grid such as grid row, header row, pager row, etc.. Try the following code:
    c#:
    protected void gvRenewal_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)   
        {   
          if(e.Item is GridDataItem) 
            { 
              GridDataItem dataItem = (GridDataItem)e.Item;  
              HyperLink lblVisitNo = (HyperLink)dataItem.FindControl("lblVisitNo");   
              int SiteID = int.Parse(Request.QueryString["SID"]);   
              lblVisitNo.NavigateUrl = "~/Pages/Sites/Management_Sites/Renewal_SiteVisits.aspx?SID=" + SiteID;  
      
            }  
        }  
     

    Thanks
    Princy.
Back to Top