473,395 Members | 1,466 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,395 software developers and data experts.

How and when can I access the controls in the pager row?

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 accesses them? My current code
is as follows:
Partial Public Class indextest : Inherits System.Web.UI.Page
Private rowcount As Integer = 0

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then Me.Refresh()
End Sub

Private Sub Refresh()
'Bind data
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()
Me.rowcount = photoalbum.Rows.Count
End Sub

Private Sub fviewPhotoAlbum_ItemCreated(ByVal sender As Object, ByVal e
As System.EventArgs) Handles fviewPhotoAlbum.ItemCreated
'Hide unnecessary numeric LinkButtons
For i As Integer = 1 To 10
CType(Me.fviewPhotoAlbum.BottomPagerRow.Cells(0).F indControl("lnkPhotoAlbum"
& CStr(i)), LinkButton).Visible = (i <= Me.rowcount)
CType(Me.fviewPhotoAlbum.BottomPagerRow.Cells(0).F indControl("lnkPhotoAlbum"
& CStr(i)), LinkButton).Text = "&nbsp;" & CStr(i) & "&nbsp;"
Next
End Sub

Private Sub fviewPhotoAlbum_PageIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles fviewPhotoAlbum.PageIndexChanged
Dim currfile As String = CType(Me.fviewPhotoAlbum.DataItem,
DataRowView)("filename").ToString()
Dim photo As System.Drawing.Image =
System.Drawing.Image.FromFile(MapPath("images/photoalbum/" & currfile))
CType(Me.fviewPhotoAlbum.FindControl("imgPhoto"), Image).Width =
photo.Width
CType(Me.fviewPhotoAlbum.FindControl("imgPhoto"), Image).Height =
photo.Height
End Sub

Private Sub fviewPhotoAlbum_PageIndexChanging(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.FormViewPageEventArgs) Handles
fviewPhotoAlbum.PageIndexChanging
Me.fviewPhotoAlbum.PageIndex = e.NewPageIndex
Me.Refresh()
End Sub
End Class
The code that I am not sure what event to put in, or whether is correct, is
the code in the fviewPhotoAlbum_ItemCreated method. I can successfully make
FormView controls with automatically generated Paging controls work, but I
cannot get the PagerTemplate to work. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Jan 26 '07 #1
5 3104
>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 accesses them? My current
code is as follows:
fromViewCtrl.FindControl('id_of_control') should rescue you.

--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------
Jan 26 '07 #2
That is what I currently use, but what event(s) is this usable in? On the
following site:

http://msdn2.microsoft.com/en-us/lib...mpagerrow.aspx

It says:

Note:
The BottomPagerRow property is available only after the FormView
control creates the bottom pager row in the ItemCreated event.

I feel like I have tried every event possible, but I either receive an error
or nothing. Keep in mind that I am trying to access the controls in the
PagerTemplate, not the ItemTemplate. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Gaurav Vaish (MasterGaurav)" <ga*****************@nospam.gmail.comwrote
in message news:eF**************@TK2MSFTNGP06.phx.gbl...
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 accesses them? My current
code is as follows:

fromViewCtrl.FindControl('id_of_control') should rescue you.

--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------


Jan 26 '07 #3
I feel like I have tried every event possible, but I either receive an
error or nothing. Keep in mind that I am trying to access the controls in
the PagerTemplate, not the ItemTemplate. Thanks.

Handle the event DataBound

fviewPhotoAlbum_DataBound(...)

Dim pager as FormViewRow = fviewPhotoAlbum.BottomPagerRow
Dim myControl as Control = pager.FindControl('lnkPhotoAlbum')

Dim btn as LinkButton = CType(myControl, LinkButton)

End Sub

HTH

--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------

Jan 26 '07 #4
I tried that, and just like the other things I tried, it just gives me an
empty browser window. Here is my exact code from my files:
indextest.aspx:

<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="indextest.aspx.vb" Inherits="family.indextest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:FormView ID="fviewPhotoAlbum" runat="server" AllowPaging="True"
HorizontalAlign="Center" Visible="false">
<PagerSettings NextPageImageUrl="images/NextBtn.gif"
PreviousPageImageUrl="images/PrevBtn.gif" Mode="NextPrevious"
Position="Bottom"/>
<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" Text="A" />
<asp:LinkButton ID="lnkPhotoAlbum2" runat="server"
CausesValidation="false" CommandName="Page" Text="B" />
<asp:LinkButton ID="lnkPhotoAlbum3" runat="server"
CausesValidation="false" CommandName="Page" Text="C" />
<asp:LinkButton ID="lnkPhotoAlbum4" runat="server"
CausesValidation="false" CommandName="Page" Text="D" />
<asp:LinkButton ID="lnkPhotoAlbum5" runat="server"
CausesValidation="false" CommandName="Page" Text="E" />
<asp:LinkButton ID="lnkPhotoAlbum6" runat="server"
CausesValidation="false" CommandName="Page" Text="F" />
<asp:LinkButton ID="lnkPhotoAlbum7" runat="server"
CausesValidation="false" CommandName="Page" Text="G" />
<asp:LinkButton ID="lnkPhotoAlbum8" runat="server"
CausesValidation="false" CommandName="Page" Text="H" />
<asp:LinkButton ID="lnkPhotoAlbum9" runat="server"
CausesValidation="false" CommandName="Page" Text="I" />
<asp:LinkButton ID="lnkPhotoAlbum10" runat="server"
CausesValidation="false" CommandName="Page" Text="J" />&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>
</form>
</body>
</html>
indextest.aspx.vb:

Partial Public Class indextest : Inherits System.Web.UI.Page
Private rowcount As Integer = 0

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then Me.Refresh()
End Sub

Private Sub Refresh()
'Bind data
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()
Me.rowcount = photoalbum.Rows.Count
'Response.Write(Me.rowcount & ControlChars.NewLine)
End Sub

Private Sub fviewPhotoAlbum_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles fviewPhotoAlbum.DataBound
'Hide unnecessary numeric LinkButtons
For i As Integer = 1 To 10
CType(Me.fviewPhotoAlbum.BottomPagerRow.FindContro l("lnkPhotoAlbum"
& CStr(i)), LinkButton).Visible = (i <= Me.rowcount)
CType(Me.fviewPhotoAlbum.BottomPagerRow.FindContro l("lnkPhotoAlbum"
& CStr(i)), LinkButton).Text = "&nbsp;" & CStr(i) & "&nbsp;"
Next
End Sub

Private Sub fviewPhotoAlbum_PageIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles fviewPhotoAlbum.PageIndexChanged
Dim currfile As String = CType(Me.fviewPhotoAlbum.DataItem,
DataRowView)("filename").ToString()
Dim photo As System.Drawing.Image =
System.Drawing.Image.FromFile(MapPath("images/photoalbum/" & currfile))
CType(Me.fviewPhotoAlbum.FindControl("imgPhoto"), Image).Width =
photo.Width
CType(Me.fviewPhotoAlbum.FindControl("imgPhoto"), Image).Height =
photo.Height
End Sub

Private Sub fviewPhotoAlbum_PageIndexChanging(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.FormViewPageEventArgs) Handles
fviewPhotoAlbum.PageIndexChanging
Me.fviewPhotoAlbum.PageIndex = e.NewPageIndex
Me.Refresh()
End Sub
End Class
You will notice that the code in my DataBound eventhandler attempts to set
the Visible property of some of the controls in the PagerTemplate. To make
sure this was not the reason for the empty browser window (although the
ItemTemplate and the other PagerTemplate controls should show anyway), I
tried it with that line commented out and with the whole DataBound event
commented out, but I still receive an empty browser window. The
Response.Write() at the end of the Refresh() method was a check to make sure
my DataSource was not empty, and it wasn't (the Response.Write() output a
3). Why can't I get this thing to work? I don't have any problems when I
don't use the PagerTemplate. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Gaurav Vaish (MasterGaurav)" <ga*****************@nospam.gmail.comwrote
in message news:%2******************@TK2MSFTNGP03.phx.gbl...
>I feel like I have tried every event possible, but I either receive an
error or nothing. Keep in mind that I am trying to access the controls in
the PagerTemplate, not the ItemTemplate. Thanks.


Handle the event DataBound

fviewPhotoAlbum_DataBound(...)

Dim pager as FormViewRow = fviewPhotoAlbum.BottomPagerRow
Dim myControl as Control = pager.FindControl('lnkPhotoAlbum')

Dim btn as LinkButton = CType(myControl, LinkButton)

End Sub

HTH

--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------

Jan 26 '07 #5
>I tried that, and just like the other things I tried, it just gives me an
>empty browser window. Here is my exact code from my files:
Let me munch it over the dinner or tomorrow breakfast... I think I need a
reboot right now.
Should work... because I just tried it out a while ago (bound to DataSet
from Customers in Northwind) :D
--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
Jan 27 '07 #6

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

Similar topics

4
by: john_20_28_2000 | last post by:
Does anyone know of anything out there that I can use to dial up a numeric pager, leave a number and then hang up? It is not a "fancy" pager. No message, not text, no nothing. Just a regular old...
2
by: Binny | last post by:
I have a datagrid with customized pager in header and footer. Is there a way to find during item created whether its for top or bottom of the Grid. thanks
2
by: Vi | last post by:
Hi, I'm building a screen where I want to allow users to be able to see data one page at a time. The users would view the data by clicking on the Page Nr. The problem is that the number of pages...
0
by: john_20_28_2000 | last post by:
Does anyone know of anything out there that I can use to dial up a numeric pager, leave a number and then hang up? It is not a "fancy" pager. No message, not text, no nothing. Just a regular old...
6
by: Alan Silver | last post by:
Hello, I have been playing with the data grid, which looks very powerful for providing paged views of your data, but I don't like the way the footer bits are displayed when there's only one...
0
by: Joey | last post by:
Hello, I need to be able to access the linkbuttons that are used for paging inside a datagrid so I can set the style for what eventually becomes the client-side html anchor tags. I have read...
1
by: Sharon | last post by:
Hi all, I'm trying to programmatically render a user control, but problem is, i don't have the control type and i cannot use register directive as the context is not an aspx page. Any ideas,...
1
by: SMichal | last post by:
Hi, I need a liitle help with build of my custom pager for gridview...I made this kind of pager..I looks like this: << < 1 2 3 4 5 6 7 8 9 10 > Well...it's no bad but I wannt something like...
2
by: =?Utf-8?B?QHdpbg==?= | last post by:
Hello There, I need to page a pager whenever an error event takes place in my app. What is the best approach in this? Should I use and modify the SerialPort class to talk to the modem. I...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.