Pagina 1 di 4 1 2 3 ... ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 36

Discussione: Solo paginazione

  1. #1

    Solo paginazione

    ciao a tutti,
    io fino ad ora ho usato il datagrid per fare la paginazione, ma fino ad ora ho fatto il pannello di controllo del sito e perciò avevo bisogno delle opzioni di editing.

    Ora invece devo fare la parte pubblica, praticamente devo far vedere i prodotti inseriti, nulla di particolare apparte che dovrò personalizzare al massimo la stampa a video con una tabella.

    Perciò quale oggetto mi consigliate per fare la paginazione? uso sempre il datagrid o cosa?

    grazie.

  2. #2

  3. #3
    Utente di HTML.it L'avatar di Umanista
    Registrato dal
    Jan 2002
    Messaggi
    1,022
    Personalmente ti consiglio di usare il datagrid solo quando non puoi farne a meno. E' meglio creare delle paginazioni manualmente con il repeater o con il dataList. Bisogna perderci un pò più di tempo, ma ne vale la pena.

  4. #4
    qualcosa da vedere e personalizzare?

  5. #5
    Utente di HTML.it L'avatar di Umanista
    Registrato dal
    Jan 2002
    Messaggi
    1,022
    '-------------------------------------------------------------------------------
    ' ******************* PAGINAZIONE ASP.NET CON DATAREADER ***********************
    ' di Umanista
    ' 23 febbraio 2003
    '-------------------------------------------------------------------------------

    'Imposta paginazione
    Const intRecordXPagina As Integer = 10
    Dim intPagine As Integer
    Dim paginaCorrente As Integer

    'Imposta la connessione
    Dim Con as new OleDbConnection (ConfigurationSettings.AppSettings("con_users"))


    Sub Page_Load(src As Object, e As EventArgs)
    Dim strCategoria As String = Request.QueryString("cat")

    If Not Page.IsPostBack Then
    'Conta le pagine
    SetTotalPages(strCategoria)
    theArray(strCategoria)
    End If


    'Imposta links della paginazione
    Dim arrMaxRecords() As String = Split(viewstate("paginazione"), "-")
    Dim getPageLinks As String
    Dim intPage As Integer

    'Raccoglie il valore del campo ID del database dell'ultimo record mostrato
    Dim currentPageIndex As String = Request.QueryString("start")

    BindDataList(currentPageIndex , strCategoria)

    If currentPageIndex = "" Then
    currentPageIndex = arrMaxRecords(0)
    End If


    If UBound(arrMaxRecords) > 1 Then
    For intPage = 1 To UBound(arrMaxRecords)

    If CurrentPageIndex <> arrMaxRecords(intPage -1) Then

    getPageLinks = getPageLinks & " <a href='show_annunci.aspx?start=" & arrMaxRecords(intPage -1) & _
    "&cat=" & strCategoria & "'>" & intPage & "</a> "

    Else

    getPageLinks = getPageLinks & "[" & intPage & "]"

    End If

    Next
    End If

    If getPageLinks <> "" Then

    lblPageLinks.Text = getPageLinks

    Else

    lblPageLinks.Text = "Nessun annuncio disponibile."

    End If

    titoloPagina.Text = strCategoria

    End Sub




    Sub SetTotalPages(ByVal categoria As String)
    '------------------------------------------
    ' Conta le pagine
    '------------------------------------------
    If Not Page.isPostBack Then

    Dim cmd As New oleDbCommand("SELECT Count(*) FROM annunci WHERE categoria = '" & categoria & "' ", Con)

    Con.Open()

    Dim reccount As Integer = cmd.ExecuteScalar().ToString()

    If reccount Mod intRecordXPagina = 0 Then
    intPagine = reccount / intRecordXPagina
    Else
    intPagine = CInt(reccount / intRecordXPagina) + 1
    End If

    Con.Close()

    End If
    End Sub


    Sub BindDataList(ByVal startRecord As Integer, ByVal categoria As String)

    Dim sqlString As String = "SELECT TOP " & intRecordXPagina & " * FROM annunci " & _
    " WHERE categoria = '" & categoria & "' AND ID > " & startRecord

    'Apri la connessione
    Dim myCommand as new OleDbCommand(sqlString, Con)
    Dim objReader as OleDbDataReader


    Con.Open()

    objReader= myCommand.ExecuteReader()

    dtlstAnnunci.Datasource= objReader
    dtlstAnnunci.DataBind()

    objReader.Close()
    Con.Close()

    End Sub

    Sub theArray(ByVal categoria As String)

    'Estraggo tutti gli id dei records e li colleziono in un array
    Dim sqlString As String = "SELECT * FROM annunci WHERE categoria = '" & categoria & " ' ORDER BY ID"

    'Apri la connessione
    Dim myCommand as new OleDbCommand(sqlString, Con)
    Dim objReader as OleDbDataReader

    Con.Open()

    objReader= myCommand.ExecuteReader()

    Dim arrRecord As new ArrayList()

    Do While objReader.Read()
    arrRecord.Add(objReader.Item(0))
    Loop

    objReader.Close()
    Con.Close()

    Dim i As integer= 0
    Dim pageLinks As String
    Dim arrPageIndex As Integer= 0

    '------------------------------------------------------------------------------
    ' Genera una stringa che contiene i numeri delle pagine separati da un trattino.
    ' Tale stringa viene poi splittata e trasformata successivamente nella Sub
    ' Page_Load per permettere la navigazione tra le pagine
    '------------------------------------------------------------------------------
    For i = 1 To (intPagine)

    'Se l'indice NON supera il limite massimo ammesso dall'Array
    If arrPageIndex < arrRecord.Count() Then

    pageLinks= pageLinks & (arrRecord(arrPageIndex) - 1) & "-"
    arrPageIndex= arrPageIndex + intRecordXPagina

    End If

    Next

    'Salva la stringa di navigazione in uno State Bag
    viewstate("paginazione") = pageLinks

    End Sub

  6. #6
    una cosa non capisco, ma la stampa a video dei dati presi dal DB dov'è?

  7. #7
    Utente di HTML.it L'avatar di Umanista
    Registrato dal
    Jan 2002
    Messaggi
    1,022
    E' nel datalist che nel mio esempio si chiama dtlstAnnunci,
    e precisamente nella Sub BindDataList

  8. #8
    poi io nel form metto un repeater e tramite i template costruisco la tabella e cosi via, vero?

    chiedo troppo se mi potresti far vedere anche il form?



    poi non capisco bene theArray....

  9. #9
    Utente di HTML.it L'avatar di Umanista
    Registrato dal
    Jan 2002
    Messaggi
    1,022
    Originariamente inviato da Daniele80
    poi io nel form metto un repeater e tramite i template costruisco la tabella e cosi via, vero?

    chiedo troppo se mi potresti far vedere anche il form?



    poi non capisco bene theArray....
    Risposta alla prima domanda: sì. Io ho usato un datalist, ma un repeter è uguale.

    Risposta alla seconda domanda: quale form?

    Risposta alla terza affermazione: theArray è il punto debole di questo script. Infatti non fa altro che memorizzare tutti gli ID dei records contenuti nel db. Non ho trovato un modo migliore. Questo script funziona correttamente, ma secondo me si può fare di meglio.

  10. #10
    non so se ti può interessare ma io mi sto guardando oltre che il tuo script anche questo:
    ricerca.ascx
    codice:
    <%@ Control debug="true"%>
    <%@ Import Namespace="System.Data"%>
    <%@ Import Namespace="System.Data.SQLClient"%>
    <SCRIPT LANGUAGE="VB" RUNAT="SERVER">
    
    Dim PageSize as Integer = 1
    Dim CurrentPage as string
    Dim TotalPages as Integer
    Dim TotalSize as Integer
    
    ' PUBLIC
    Dim Public Chiave as String
    
    Sub Page_Load(sender As Object, e As EventArgs)
    
    	' recupero chiave da querystring se non è passata dal control
    	if chiave is nothing then
    		chiave = Request("chiave")
    	end if
    
    	' pagina corrente
    	CurrentPage = Request("p")
    	if CurrentPage is nothing then CurrentPage = 1
    	if not page.ispostback then
    		binddata()
    	end if
    End Sub
    
    Sub BindData()
    
    	' stringa di connessione
    	Dim strconn as String = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("mdb-database/fg-tunisie.mdb")
    
    	' query
    	Dim strSQL as String = "SELECT * FROM Prodotti WHERE Categoria LIKE '%" & chiave.Replace("'", "''") & "%'"
    
    	' SqlConnection e SqlDataAdapter
    	Dim conn as OleDbConnection = New OleDbConnection(strConn) 
    	Dim query As OleDbDataAdapter = New OleDbDataAdapter(strSQL, conn) 
     
    	' creo il dataset 
    	Dim querydataset As Dataset = new DataSet() 
     	Dim startRecord as integer = (int32.Parse(CurrentPage) - 1) * int32.Parse(PageSize)
    
    	' databinding
    	query.Fill(querydataset, startRecord, int32.Parse(PageSize), "ext_content")
    	queryres.DataSource = querydataset 
    	queryres.DataBind() 
    
    	' conta i record totali
    	Dim strSQLCount as String = strSQL
    
    	' ricavo la query count
    	strSQLCount = "SELECT COUNT(*) as Totale " & strSQLCount.SubString(strSQLCount.IndexOf(" FROM Prodotti WHERE Categoria LIKE '%" & chiave.Replace("'", "''") & "%'"))
    
    	conn.open
    	Dim myCommand as OleDbCommand = New OleDbCommand(strSQLCount, Conn)
    	Dim reader as OleDbDataReader = myCommand.ExecuteReader()
    
    	' conto i risultati
    	reader.read()
    	TotalSize = reader("totale")
    
    	reader.Close
    	conn.Close
    
    	' mostra avviso in alto con il numero dei risultati
    	if TotalSize = 0 then
    		results.text = "Non ci sono risultati per questa ricerca"
    	else
    		TotalPages = int32.Parse(TotalSize)\int32.Parse(PageSize)+1
    
    		' fix per numero di pagine
    		if Fix(TotalSize/PageSize) = TotalSize/PageSize then TotalPages = TotalPages -1
    
    		if TotalSize =1 then
    			results.text += "Un risultato"
    		else
    			results.text += TotalSize & " risultati"
    		end if
    
    		' fix per record finale
    		Dim EndRecors as Integer = startRecord + int32.Parse(PageSize)
    		if EndRecords > TotalSize then EndRecords = TotalSize
    
    		results.text += " - Pagina " &  CurrentPage & " su " & TotalPages & " in totale - da " &  startRecord+1 & " a " & 
    	end if
    
    	if totalsize = 0 then
    		paginazione.visible = false
    	end if
    
    	' costruisci la paginazione
    	BuildPagers()
    End Sub
    
    Sub BuildPagers()
    
    	' ciclo
    	dim i as integer
    	dim lb as Label
    
    	if TotalPages> 1 then
    		lb = New Label()
    		lb.Text = "Ci sono " & TotalPages & " pagine con i risultati: "
    		paginazione.controls.add(lb)
    
    		for i = 1 to (TotalPages)
    			lb = New Label()
    			lb.id = "ThisPage" & i
    			if currentPage = i then
    				lb.text = "[" & i & "] " & VbCrLf
    			else
    				lb.text = "[" & i & "] " & VbCrLf
    			end if
    			paginazione.controls.add(lb)
    		next
    	end if
    End sub
    
    </SCRIPT>
    
    <asp:label id="results" runat="server"/>
    
    <asp:repeater id="queryres" runat="server">
    <itemTemplate>
    <%#Container.DataItem("codice")%> - 
    <%#Container.DataItem("titolo")%>
    </itemTemplate>
    </asp:repeater>
    
    
    
    
    <asp:placeholder id="Paginazione" runat="server"/>
    ricerca.aspx
    codice:
    <%@ Register TagPrefix="tools" TagName="ricerca" src="ricerca.ascx"%>
    
    <h1>Ricerca</h1>
    
    <tools:ricerca chiave="gomme" runat="server"/>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.