N
Nathan Sokalski
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 = " " & CStr(i) & " "
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.
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 = " " & CStr(i) & " "
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.