Programmatically modifying the controls in FormView's PagerTemplate

Discussion in 'ASP .Net Web Controls' started by Nathan Sokalski, Jan 13, 2007.

  1. I am trying to create a FormView controls in which I access and modify the
    the controls in the PagerTemplate programmatically. However, I continue to
    recieve the following error:

    Object reference not set to an instance of an object.

    I am attempting to access the controls in my PagerTemplate using the
    following code:

    CType(Me.fviewPhotoAlbum.FindControl("lnkPhotoAlbum"), LinkButton)


    I have tried doing this from all the events that I could think of and that I
    noticed mentioned on any help sites I could find, but it didn't help. I
    don't know what I am doing wrong, if anyone could help me I would greatly
    appreciate it. Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Jan 13, 2007
    #1
    1. Advertising

  2. Because this is my first time using the FormView control (although I have
    had plenty of experience with the DataList control, so I have used templates
    before), I tried putting it in the Page's Load eventhandler. Something that
    I saw on the Internet said to put it in the FormView control's ItemCreated
    eventhandler, but that didn't work either. Here is the code I have in my
    Page's Load eventhandler:

    Private Sub index_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Handles Me.Load

    Dim photoalbum As New DataTable

    Dim dataadapterSelect As New System.Data.OleDb.OleDbDataAdapter("SELECT *
    FROM babyphotos ORDER BY photodate,filename",
    System.Configuration.ConfigurationManager.AppSettings("connectionstring"))

    dataadapterSelect.Fill(photoalbum)

    Me.fviewPhotoAlbum.DataSource = photoalbum

    Me.fviewPhotoAlbum.DataBind()

    'Hide unnecessary numeric LinkButtons

    For i As Integer = 1 To 10

    CType(Me.fviewPhotoAlbum.FindControl("lnkPhotoAlbum" & CStr(i)),
    LinkButton).Visible = (i <= photoalbum.Rows.Count)

    Next

    End Sub


    The basic goal of this code is to not show more numeric controls than
    necessary (I don't want to show 10 controls if there are only 5 records).
    Here is my FormView control:

    <asp:FormView ID="fviewPhotoAlbum" runat="server" AllowPaging="True"
    HorizontalAlign="Center">

    <PagerSettings NextPageImageUrl="images/NextBtn.gif"
    PreviousPageImageUrl="images/PrevBtn.gif" Mode="NextPrevious"/>

    <rowstyle HorizontalAlign="Center"/>

    <ItemTemplate>

    <asp:Image ID="imgPhoto" runat="server" BorderWidth="0px"
    ImageAlign="Middle" ImageUrl='<%#
    DataBinder.Eval(Container,"DataItem.filename","images/photoalbum/{0}")
    %>'/><br/>

    <asp:Label ID="lblPhotoCaption" runat="server"
    AssociatedControlID="imgPhoto" Text='<%#
    DataBinder.Eval(Container,"DataItem.caption") %>'/><br/>

    <asp:Label ID="lblPhotoDate" runat="server" AssociatedControlID="imgPhoto"
    Text='<%# DataBinder.Eval(Container,"DataItem.photodate","Photo taken on:
    {0:D}") %>'/>

    </ItemTemplate>

    <PagerTemplate>

    <asp:ImageButton ID="imgPrevious" runat="server" AlternateText="Previous
    Photo" BorderWidth="0px" CausesValidation="False" CommandArgument="Prev"
    CommandName="Page" Height="35px" ImageUrl="images/PrevBtn.gif"
    Width="35px"/>&nbsp;

    <asp:LinkButton ID="lnkPhotoAlbum1" runat="server" CausesValidation="false"
    CommandName="Page"/>

    <asp:LinkButton ID="lnkPhotoAlbum2" runat="server" CausesValidation="false"
    CommandName="Page"/>

    <asp:LinkButton ID="lnkPhotoAlbum3" runat="server" CausesValidation="false"
    CommandName="Page"/>

    <asp:LinkButton ID="lnkPhotoAlbum4" runat="server" CausesValidation="false"
    CommandName="Page"/>

    <asp:LinkButton ID="lnkPhotoAlbum5" runat="server" CausesValidation="false"
    CommandName="Page"/>

    <asp:LinkButton ID="lnkPhotoAlbum6" runat="server" CausesValidation="false"
    CommandName="Page"/>

    <asp:LinkButton ID="lnkPhotoAlbum7" runat="server" CausesValidation="false"
    CommandName="Page"/>

    <asp:LinkButton ID="lnkPhotoAlbum8" runat="server" CausesValidation="false"
    CommandName="Page"/>

    <asp:LinkButton ID="lnkPhotoAlbum9" runat="server" CausesValidation="false"
    CommandName="Page"/>

    <asp:LinkButton ID="lnkPhotoAlbum10" runat="server" CausesValidation="false"
    CommandName="Page"/>&nbsp;

    <asp:ImageButton ID="imgNext" runat="server" AlternateText="Next Photo"
    BorderWidth="0px" CausesValidation="False" CommandArgument="Next"
    CommandName="Page" Height="35px" ImageUrl="images/NextBtn.gif"
    Width="35px"/>

    </PagerTemplate>

    </asp:FormView>


    Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Gaurav Vaish (MasterGaurav)" <> wrote
    in message news:...
    >> I am attempting to access the controls in my PagerTemplate using the
    >> following code:
    >>
    >> CType(Me.fviewPhotoAlbum.FindControl("lnkPhotoAlbum"), LinkButton)

    >
    > Where are you writing this code? I mean.. in which event-handler / method?
    >
    >
    > --
    > Happy Hacking,
    > Gaurav Vaish | www.mastergaurav.com
    > www.edujini-labs.com
    > http://eduzine.edujinionline.com
    > -----------------------------------------
    >
    >
     
    Nathan Sokalski, Jan 15, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski
    Replies:
    0
    Views:
    422
    Nathan Sokalski
    Jan 11, 2007
  2. Nathan Sokalski
    Replies:
    2
    Views:
    2,094
    Nathan Sokalski
    Jan 15, 2007
  3. Nathan Sokalski

    Accessing the controls in the PagerTemplate when using FormView

    Nathan Sokalski, Jan 11, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    753
    Nathan Sokalski
    Jan 11, 2007
  4. Nathan Sokalski

    Programmatically modifying the controls in FormView's PagerTemplate

    Nathan Sokalski, Jan 13, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    730
    Nathan Sokalski
    Jan 15, 2007
  5. Nathan Sokalski

    Accessing the controls in the PagerTemplate when using FormView

    Nathan Sokalski, Jan 11, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    300
    Nathan Sokalski
    Jan 11, 2007
Loading...

Share This Page