PsychoCoder
Programmer
I have a page where Im trying to bind a repeater, the code for binding said repeater is as follows:
The object I'm using in this sub are declared at the top of the page:
At first I thought my sub wasnt returning any rows (as the page was blank) but that was because of the empty Catch, which wasnt allowing any errors to show. I removed that line and get this error:
The HTML code for the repeater is:
I have bolded the line where lblCurrentPage does indeed exist. So why is FindControl not working? Anyone have any ideas?
By the way, CurrentPage is a property in the code behind:
Can someone please help me with this
Senior Qik III, ASP.Net, VB.Net ,SQL Programmer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Code:
Protected Sub GetApps()
sSQL = "SELECT "
sSQL &= "RTRIM(column1) as 'change_id',RTRIM(column2) as 'app_name',RTRIM(column3) as 'app_description',"
sSQL &= "RTRIM(column4) as 'app_developer',RTRIM(CONVERT(VARCHAR(15),column5)) as 'app_completition_date' "
sSQL & = " **Table_Name** "
sSQL &= "ORDER BY date_entered"
Command = New SqlCommand(sSQL, Connection)
Command.CommandType = CommandType.Text
DAdapter = New SqlDataAdapter
DAdapter.SelectCommand = Command
DS = New DataSet
Try
Connection.Open()
DAdapter.Fill(DS, "**Table_Name**")
Pager.DataSource = DS.Tables("**Table_Name**").DefaultView
Pager.AllowPaging = True
Pager.PageSize = 25
Pager.CurrentPageIndex = CurrentPage
CType(Me.current_apps.FindControl("lblCurrentPage"), Label).Text = "Page: " + (CurrentPage + 1).ToString + " of " + Pager.PageCount.ToString
cmdPrev.Enabled = Not Pager.IsFirstPage
cmdNext.Enabled = Not Pager.IsLastPage
current_apps.DataSource = Pager
current_apps.DataMember = "column1"
current_apps.DataBind()
Catch ex As Exception
End Try
End Sub
Code:
Private Shared Conn As String = Common.GetConnectionString("api_sap")
Private Shared Connection As New SqlConnection(Conn)
Private Command As SqlCommand
Private Shared DReader As SqlDataReader
Private Shared DAdapter As SqlDataAdapter
Private Pager As PagedDataSource = New PagedDataSource
Private DS As DataSet
Private Shared sSQL As String
At first I thought my sub wasnt returning any rows (as the page was blank) but that was because of the empty Catch, which wasnt allowing any errors to show. I removed that line and get this error:
Code:
Object reference not set to an instance of an object.
[b]Description:[/b] An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
[b]Exception Details:[/b] System.NullReferenceException: Object reference not set to an instance of an object.
[b]Source Error: [/b]
Line 47: Pager.PageSize = 25
Line 48: Pager.CurrentPageIndex = CurrentPage
[b]Line 49: CType(Me.current_apps.FindControl("lblCurrentPage"), Label).Text = "Page: " + (CurrentPage + 1).ToString + " of " + Pager.PageCount.ToString[/b]
Line 50: cmdPrev.Enabled = Not Pager.IsFirstPage
Line 51: cmdNext.Enabled = Not Pager.IsLastPage
The HTML code for the repeater is:
Code:
<ASP:REPEATER ID="current_apps" RUNAT="server" DATAMEMBER="change_id" VISIBLE="true" >
<HEADERTEMPLATE>
<table id="header" width="100%" cellpadding="2" cellspacing="2" class="list_header">
<tr>
<td colspan="5">
[b]<ASP:LABEL ID="lblCurrentPage" RUNAT="server" TEXT="Label"/>[/b]</td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td style="WIDTH: 100px"> </td>
<td><ASP:LABEL ID="Label2" RUNAT="server" TEXT="Application Name"/></td>
<td><ASP:LABEL ID="Label3" RUNAT="server" TEXT="Description"/></td>
<td><ASP:LABEL ID="Label4" RUNAT="server" TEXT="Developer"/></td>
<td><ASP:LABEL ID="Label5" RUNAT="server" TEXT="Completition Date"/></td>
</tr>
</table>
</HEADERTEMPLATE>
<ITEMTEMPLATE>
<table id="header" cellpadding="2" cellspacing="2" width="100%">
<tr>
<td style="WIDTH: 100px">
<ASP:LINKBUTTON ID="lnkSelect" RUNAT="server" TEXT="Edit" COMMANDNAME="Edit"/></td>
<td><ASP:LABEL ID="Label2" RUNAT="server" TEXT='<%# DataBinder.Eval(Container.DataItem,"app_name") %>'/></td>
<td><ASP:LABEL ID="Label3" RUNAT="server" TEXT='<%# DataBinder.Eval(Container.DataItem,"app_description") %>'/></td>
<td><ASP:LABEL ID="Label4" RUNAT="server" TEXT='<%# DataBinder.Eval(Container.DataItem,"app_developer") %>'/></td>
<td><ASP:LABEL ID="Label5" RUNAT="server" TEXT='<%# DataBinder.Eval(Container.DataItem,"app_completition_date") %>'/></td>
</tr>
</table>
</ITEMTEMPLATE>
</ASP:REPEATER>
I have bolded the line where lblCurrentPage does indeed exist. So why is FindControl not working? Anyone have any ideas?
By the way, CurrentPage is a property in the code behind:
Code:
Public Property CurrentPage() As Integer
Get
Dim o As Object = Me.ViewState("_CurrentPage")
If o Is Nothing Then
Return 0
Else
Return CType(o, Integer)
End If
End Get
Set(ByVal value As Integer)
Me.ViewState("_CurrentPage") = value
End Set
End Property
Can someone please help me with this
Senior Qik III, ASP.Net, VB.Net ,SQL Programmer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~