PC Review


Reply
Thread Tools Rate Thread

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

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      26th Jan 2007
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.AppSettings("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).FindControl("lnkPhotoAlbum"
& CStr(i)), LinkButton).Visible = (i <= Me.rowcount)
CType(Me.fviewPhotoAlbum.BottomPagerRow.Cells(0).FindControl("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
(E-Mail Removed)
http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
Gaurav Vaish \(MasterGaurav\)
Guest
Posts: n/a
 
      26th Jan 2007
>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
-----------------------------------------


 
Reply With Quote
 
Nathan Sokalski
Guest
Posts: n/a
 
      26th Jan 2007
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
(E-Mail Removed)
http://www.nathansokalski.com/

"Gaurav Vaish (MasterGaurav)" <(E-Mail Removed)> wrote
in message news:eFJJi$(E-Mail Removed)...
> >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
> -----------------------------------------
>
>





 
Reply With Quote
 
Gaurav Vaish \(MasterGaurav\)
Guest
Posts: n/a
 
      26th Jan 2007
> 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
-----------------------------------------



 
Reply With Quote
 
Nathan Sokalski
Guest
Posts: n/a
 
      26th Jan 2007
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","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}")
%>'/>
</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.AppSettings("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.FindControl("lnkPhotoAlbum"
& CStr(i)), LinkButton).Visible = (i <= Me.rowcount)
CType(Me.fviewPhotoAlbum.BottomPagerRow.FindControl("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
(E-Mail Removed)
http://www.nathansokalski.com/

"Gaurav Vaish (MasterGaurav)" <(E-Mail Removed)> wrote
in message news:%23xP3%(E-Mail Removed)...
>> 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
> -----------------------------------------
>
>
>



 
Reply With Quote
 
Gaurav Vaish \(www.edujini-labs.com\)
Guest
Posts: n/a
 
      27th Jan 2007
>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)


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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Restricting Access to Controls Based on Information from other Controls Jason Lopez Microsoft Access Forms 0 12th Jul 2007 08:24 PM
Access Hyperlinks/LinkButtons in Datagrid Pager Joey Microsoft ASP .NET 0 23rd Jan 2006 05:42 PM
Web Controls/User Controls - Access Modifier Mr Newbie Microsoft ASP .NET 3 31st Oct 2005 04:01 PM
How can dynamic controls access static controls? Fred White Microsoft VB .NET 7 5th Dec 2003 02:45 PM
Pager Tim Gallivan Microsoft VB .NET 4 30th Oct 2003 06:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:32 AM.