473,387 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Programmatically modifying the controls in FormView's PagerTemplate

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("lnkPhotoAlbu m"), 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
nj********@hotmail.com
http://www.nathansokalski.com/
Jan 13 '07 #1
2 2546
I am attempting to access the controls in my PagerTemplate using the
following code:

CType(Me.fviewPhotoAlbum.FindControl("lnkPhotoAlbu m"), 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
-----------------------------------------
Jan 14 '07 #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.AppSetti ngs("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("lnkPhotoAlbu m" & 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","ima ges/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","Ph oto 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
nj********@hotmail.com
http://www.nathansokalski.com/

"Gaurav Vaish (MasterGaurav)" <ga*****************@nospam.gmail.comwrote
in message news:uI*************@TK2MSFTNGP03.phx.gbl...
>I am attempting to access the controls in my PagerTemplate using the
following code:

CType(Me.fviewPhotoAlbum.FindControl("lnkPhotoAlb um"), 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
-----------------------------------------


Jan 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: clintonG | last post by:
Briefly stated, my problem is accessing and 'setting' properties of a label control declared in the template of another control noting that the other control is an instance of the beta 2...
2
by: wikkiwikkiwaa | last post by:
hello, i am trying to access controls inside my formview1 nested inside loginview1. you cannot access the formview1 unless you are properly logged in. for loginview1, that seems to be fairly...
3
by: nicomp | last post by:
Hello, I have a FormView control that has a CheckBoxList in the Item template... I wrote this code to access a CheckBoxList in a FormView template... dim foo as checkboxlist foo = ...
0
by: namewitheldbyrequest | last post by:
Hello, I have a FormView control that has a CheckBoxList in the Item template... I wrote this code to access a CheckBoxList in a FormView template... dim foo as checkboxlist foo = ...
1
by: Vincent | last post by:
The subject says it all...I keep trying to modify one of my reports programmatically. The new controls are added to the report successfully, but if I try to do anything with the report, such as...
0
by: Nathan Sokalski | last post by:
I am using a FormView control, and want to access the controls I have created in the PagerTemplate. Right now, I am doing this using the following method: ...
2
by: Nathan Sokalski | last post by:
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...
6
by: Nathan Sokalski | last post by:
I have tried everything I can think of, I have even tried copying examples from books and websites I have found, but every Formview control that I have tried to create does not show the Paging...
5
by: Nathan Sokalski | last post by:
I have a FormView control in which I use a PagerTemplate. I am having trouble accessing the controls in the PagerTemplate. How do I access them, and in what event should I put the could that...
3
by: =?Utf-8?B?QW5nZWw=?= | last post by:
I seem to understand how the control works as long as I mated to SqlDataSource or ObjDataSource it works fine. But I do not want to flatten my design in this manner. I am interested in how I can...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.