Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding a Repeater

Status
Not open for further replies.

PsychoCoder

Programmer
May 31, 2006
140
US
I have a repeater on my page that Im trying to bind, I have this sub that gets the data for me:
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("Turbo_Change_Log").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

The object I'm using in this sub are declared at the top of the page:
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

I trying to get the value like this in the aspx page:
Code:
<ASP:LABEL ID="Label2" RUNAT="server" TEXT='<%# DataBinder.Eval(Container.DataItem,"app_name") %>'></ASP:LABEL>

But I'm just getting a blank page. Any ideas?

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Code:
    DAdapter.Fill(DS, "**Table_Name**")
    Pager.DataSource = DS.Tables("Turbo_Change_Log").DefaultView
You are using a different table name for the DataSet and Pager.



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8msm,

Actually I just forgot to remove the table name from that line of code.

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Post the code you are actually using rather than us having to guess that some bits may not be correct.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8msm,

This is the entire sub that extracts the info from the database. (Same as my first post):
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

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
OK, so when you step through the code and look at the "DS.Tables("**Table_Name**")" object, does it have any rows? Once you assigned it to the pager, again, does the pager object have any rows?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8msm, yes on both counts, when I step trhough at both junctions there are rows present (2, which is the number of records)

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
What does the generated markup look like?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
On this server I cant seem to do debugging so I had it write out the values for me, Pager.Count returned 2, DS.Tables(0).Rows.Count returned 2 (which of course if the number of records I have added to the table)

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Come to find out it wasnt the binding that was causing the problem, read Thread 1306438

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top