Here is where im going to use paging with the repeater.
http://www.citimatch.com/Search4.aspx Yeah the way I figure it works on my site that is would be that you do your search and hit the button to get the search results. It would then load the records that qualify via the sql string into that dataset. Then I would need to count the total number of records and put that into a variable such as TotalRecords. Another variable names StartRecord and EndRecord. The first time a page with results are show the StartRecord would be 1 as the first record and EndRecord would be 20 to show 20 per page. Then a link would be generated with and depending on TotalRecords being more than 20 records to even need another page would Search4.aspx?StartRecord=20&EndRecord=40. Of course there would be a routine to check total records to make sure there is 40 in there to even make the link EndRecord = 40 say for instance the total in the dataset is 35 then EndREcord would be 35. If there were 150 results and TotalRecords = 150 then of course it would keep incrementing by 20 until the end. A big question is how to I count the records that are loaded into the dataset and also keeping it open to increment through it on postbacks? Once it is loaded I assume I can work with it all I want. Does this method I have made up seem workable? Are there any Improvements that can be made to it? I am open to all suggestions. HERE IS MY CODE THAT IS RUN WHEN THE USERS INITIATES THE SEARCH. <code> Private Sub ButtonSubmitSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSubmitSearch.Click 'Setup Variables Dim strGender Dim strSeeking Dim strMin_age Dim strMax_age Dim strS_state, strS_stateSQL Dim strZipcode, strZipcodeSQL Dim strS_country, strS_countrySQL Dim strUsername strUsername = Session("Username") Dim strPasswordTest strPasswordTest = "scooby1" 'Build SQL String Dim strSQLstring As String '----------------- GENDER SEEKING GENDER ------------------------ If SearchGender.SelectedValue = "Male Seeking a Female" Then 'Response.Write("SearchGender = Male Seeking a Female<BR>") strGender = "Female" strSeeking = "Male" ElseIf SearchGender.SelectedValue = "Male Seeking a Male" Then 'Response.Write("SearchGender = Male Seeking a Male<BR>") strGender = "Male" strSeeking = "Male" ElseIf SearchGender.SelectedValue = "Male Seeking a TS/TV/TG (Transgender)" Then 'Response.Write("SearchGender = Male Seeking a Male<BR>") strGender = "TS/TV/TG (Transgender)" strSeeking = "Male" '=========================================================================== ================= ElseIf SearchGender.SelectedValue = "Female Seeking a Male" Then 'Response.Write("SearchGender = Female Seeking a Male<BR>") strGender = "Male" strSeeking = "Female" ElseIf SearchGender.SelectedValue = "Female Seeking a Female" Then 'Response.Write("SearchGender = Female Seeking a Female<BR>") strGender = "Female" strSeeking = "Female" ElseIf SearchGender.SelectedValue = "Female Seeking a TS/TV/TG (Transgender)" Then 'Response.Write("SearchGender = Male Seeking a Male<BR>") strGender = "TS/TV/TG (Transgender)" strSeeking = "Female" '=========================================================================== ================= ElseIf SearchGender.SelectedValue = "TS/TV/TG (Transgender) Seeking a Female" Then 'Response.Write("SearchGender = Male Seeking a Male<BR>") strGender = "Female" strSeeking = "TS/TV/TG (Transgender)" ElseIf SearchGender.SelectedValue = "TS/TV/TG (Transgender) Seeking a Male" Then 'Response.Write("SearchGender = Male Seeking a Male<BR>") strGender = "Male" strSeeking = "TS/TV/TG (Transgender)" ElseIf SearchGender.SelectedValue = "TS/TV/TG (Transgender) Seeking a TS/TV/TG (Transgender)" Then 'Response.Write("SearchGender = Male Seeking a Male<BR>") strGender = "TS/TV/TG (Transgender)" strSeeking = "TS/TV/TG (Transgender)" Else End If '----------------------------------------------------------------- '----------------- Min_age and Max_age ------------------------ strMin_age = min_age.SelectedValue strMax_age = max_age.SelectedValue 'Response.Write("Between Ages of " & strMin_age & " and " & strMax_age & "<BR>") '----------------------------------------------------------------- '----------------- s_state ------------------------ strS_state = s_state.SelectedValue 'Response.Write("State = " & strS_state & "<BR>") If s_state.SelectedValue = "n/a" Then strS_stateSQL = "" Else strS_stateSQL = "" & " And [state] = '" & strS_state & "'" End If '----------------------------------------------------------------- '----------------- ZIPCODE ------------------------ strZipcode = ZIPCODE.Text 'Response.Write("Zipcode = " & strZipcode & "<BR>") If ZIPCODE.Text = "" Then strZipcodeSQL = "" Else strZipcodeSQL = "" & " And [Zipcode] = '" & strZipcode & "'" End If '----------------------------------------------------------------- '----------------- s_country ------------------------ strS_country = s_country.SelectedValue 'Response.Write("Country = " & strS_country & "<BR>") If s_country.SelectedValue = "n/a" Then strS_countrySQL = "" Else strS_countrySQL = "" & " And [country] = '" & strS_country & "'" End If '----------------------------------------------------------------- strSQLstring = "SELECT * FROM users WHERE [Gender] = '" & strGender & "' And [Seeking] = '" & strSeeking & "' AND ([age] BETWEEN '" & strMin_age & "' AND '" & strMax_age & "')" strSQLstring = strSQLstring & strS_stateSQL strSQLstring = strSQLstring & strZipcodeSQL strSQLstring = strSQLstring & strS_countrySQL 'Response.Write("strSQLstring = " & strSQLstring & "<BR>") 'Open the Connection ------------------------------------- Dim objConn As SqlConnection Dim objConnString As String = "Data Source=localhost;Initial Catalog=123;User Id=123;Password=123;" objConn = New SqlClient.SqlConnection(objConnString) objConn.Open() 'Create a DataSet ---------------------------------------- Dim objDataSet As New DataSet 'Create a DataSet ---------------------------------------- 'Create a DataAdapter ------------------------------------ Dim objDataAdapter As SqlDataAdapter objDataAdapter = New SqlDataAdapter(strSQLstring, objConn) objDataAdapter.Fill(objDataSet, "users") 'Create a DataAdapter ------------------------------------ 'CODE =============================================================== RepeaterListMembers.DataSource = objDataSet RepeaterListMembers.DataBind() 'CODE =============================================================== 'Response.Write("its Posted back now") PanelSearch.Visible = False PanelSearchResults.Visible = True PanelSearchNoRecords.Visible = False 'Close things up ------------------------------------ objDataSet.Dispose() objDataSet = Nothing objDataAdapter = Nothing objConn.Close() objConn = Nothing 'Close things up ------------------------------------ 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX End Sub </code> -----Original Message----- From: Mark E [mailto:[EMAIL PROTECTED] Sent: Thursday, March 31, 2005 7:49 AM To: [email protected] Subject: Re: [AspNetAnyQuestionIsOk] repeaters and paging Mike, I did this over a year ago although I'm not sure if it's simple or not. But I'll give it a try. Here my repeater control: <asp:Repeater id="rptContributionList" runat="server"> <HeaderTemplate> <table border="1"> </HeaderTemplate> <ItemTemplate> <tr bgcolor="#ffffff"> <td> <%# Container.DataItem("Date_Received") %> </td> <td> <%# Container.DataItem("Amount_Requested") %> </td> <td> <%# Container.DataItem("Amount_Paid") %> </td> <td> <%# Container.DataItem("Date_Issued") %> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> <asp:Label ID="lblNavigation" Runat="server"></asp:Label> Here is my code that binds the data to the repeater control: Public Sub LoadPagedContributionList(ByVal strPageNumber as String, ByVal strNumOfRecsPerPage as String, ByVal rptRepeaterControl as Repeater) Dim objConn As SqlConnection Dim objSQLCommand As SqlCommand Dim objDataReader As SqlDataReader Dim objParam As SqlParameter 'Set up our connection object and SQL command object. objConn = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString")) objSQLCommand = New SqlCommand("CCT_s_GetAllContributionsPaged", objConn) 'Set the stored procedure. objSQLCommand.CommandType = CommandType.StoredProcedure 'Add parameters... objParam = objSQLCommand.Parameters.Add("@Page_Number", strPageNumber) objParam = objSQLCommand.Parameters.Add("@Records_Per_Page", strNumOfRecsPerPage) 'Open the db connection. objConn.Open() 'Execute the procedure. objDataReader = objSQLCommand.ExecuteReader() 'Now bind the data to the dropdownlist. rtpRepeater.DataSource = objDataReader rtpRepeater.DataBind() 'Close the DB connection. objConn.Close() objDataReader.Close() End Sub Don't forget your imports needed to hit the sql server database: Imports System.Data Imports System.Data.SqlClient You'll notice that I pass in 2 values, Page_Number and Records_Per_Page. You can hard-code the value for Records_Per_Page in the page or in your stored procedure. I just wanted this to be a little more flexible. Anyhow, let's move on to the code that is called when the page loads: Dim strPageNumber As String = Request.QueryString("PageNum") 'Check the page number... If strPageNumber = "" Then 'No page number (ID) present. Set it to one to indicate page 1. strPageNumber = "1" End If 'Get any value for number of recs per page into a variable. Dim strNumOfRecsPerPage As String = Request.QueryString("RecsPerPage") Here is where I make the call to the above database code to bind the data to the control: LoadPagedContributionList(strPageNumber, strNumOfRecsPerPage, rptRepeaterControl) And here is the call to load the links to get to page 1, 2, 3, etc. 'Call sub that loads the paging links at the bottom of the page. DisplayPagingLinks(strNumOfRecsPerPage, strPageNumber) Private Sub DisplayPagingLinks(ByVal strNumOfRecsPerPage As String, ByVal strPageNumber As String) 'Call a method that returns the ttl record count. Dim intTotalRecordCount As Integer = GetTotalNumberOfContributionRequests() 'Now let's get the max number of pages that we can have. Dim intMaxNumberOfPages As Integer = (intTotalRecordCount / strNumOfRecsPerPage) If intMaxNumberOfPages Mod strNumOfRecsPerPage <> 0 Then intMaxNumberOfPages += 1 End If 'Now loop and set the links to the label used for paging. Dim intLoopCounter As Integer For intLoopCounter = 1 To intMaxNumberOfPages - 1 lblNavigation.Text += (" <a href=""ContributionList.aspx?PageID=" & intLoopCounter & "&RecsPerPage=" & strNumOfRecsPerPage & """>" & intLoopCounter & "</a> ") Next End Sub I hope you can make your way through the code. There's so much within the page that I did that is was nearly impossible to send the whole thing. But if you really need a full example, I can take the code and put it into it's own VS.NET project and send it to you.] Mark Mike Belcher <[EMAIL PROTECTED]> wrote: Anyone have or know of an simple example of paging records with a repeater control? mike Yahoo! Groups SponsorADVERTISEMENT --------------------------------- Yahoo! Groups Links To visit your group on the web, go to: http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/ To unsubscribe from this group, send an email to: [EMAIL PROTECTED] Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. [Non-text portions of this message have been removed] Yahoo! Groups Links http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/ [EMAIL PROTECTED] http://docs.yahoo.com/info/terms/ [Non-text portions of this message have been removed] Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
