Visualizzazione dei risultati da 1 a 6 su 6

Discussione: page_load e codebehind

  1. #1

    page_load e codebehind

    voglio trasformare una pagina di ricerca che ho fatto in un codebehind, ma quello che facevo prima con page_load ora non funziona più...ho provato a mettere page_init, ma niente lo stesso
    posto il codice..
    codice:
    imports system
    imports System.Data
    imports system.web
    imports system.web.ui
    imports system.web.ui.webcontrols
    imports corelab.mysql
    
    public class ricerca : inherits Page
        public lblErrore as label
        public tbxMarca as textBox
        public tbxCodice as textBox
        public rfvCodice as requiredfieldvalidator
        public DataGrid1 as dataGrid
    
    
        Dim connessione As New mySqlConnection("User=admin; pwd=pass; Host=localhost; Port=3306; Database=gestione_ordini")
        
        sub page_load (obj as object, e as eventargs)
            if page.ispostback then
                datagrid1.CurrentPageIndex = 0
                dim myInsertQuery as string
        
                if tbxMarca.text = "" then
                    myInsertQuery = "SELECT * FROM tbllistinonazionale WHERE codice_prodotto_produttore LIKE "& server.htmldecode (""") &""&"%"&""& tbxCodice.text &""&"%"&""& server.htmldecode (""") &";"
                else
                    myInsertQuery = "SELECT * FROM tbllistinonazionale WHERE codice_prodotto_produttore LIKE "& server.htmldecode (""") &""&"%"&""& tbxCodice.text &""&"%"&""& server.htmldecode (""") &" AND sigla_marchio = "& server.htmldecode (""") & tbxMarca.text & server.htmldecode (""") &";"
                end if
        
                Dim myCommand As New mySqldataadapter(myInsertQuery, connessione)
        
                dim ds as dataset = new dataset()
        
                mycommand.fill(ds, "tbllistinonazionale")
        
                datagrid1.datasource=ds
                datagrid1.databind()
                connessione.close
            end if
        end sub
        
        sub DataGrid1_PageIndexChanged(obj as Object, e as DataGridPageChangedEventArgs)
           DataGrid1.CurrentPageIndex = e.NewPageIndex
           DataGrid1.DataBind()
        end sub
    end class
    e questa è la pagina aspx:
    codice:
    <%@ Page Inherits="ricerca" Src="codice\ricerca.vb" %>
    <html>
    <head>
    </head>
    <body>
        <form runat="server">
            
    
    
                <asp:label id="lblErrore" runat="server" ForeColor="Red"></asp:label>
            </p>
            
    
    
                <table>
                    <tbody>
                        <tr>
                            <td>
                                Marca:</td>
                            <td>
                                <asp:TextBox id="tbxMarca" runat="server" autopostback="true"></asp:TextBox>
                            </td>
                            <td>
                                <asp:Button id="btCerca" onclick="cerca" runat="server" Text="Button"></asp:Button>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Codice Prodotto:</td>
                            <td>
                                <asp:textbox id="tbxCodice" runat="server" autopostback="true"></asp:textbox>
                            </td>
                            <td>
                                <asp:RequiredFieldValidator id="rfvCodice" runat="server" ControlToValidate="tbxCodice" ErrorMessage="Devi inserire un codice"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                    </tbody>
                </table>
                
    
                <asp:DataGrid id="DataGrid1" runat="server" BorderColor="black" Font-NameFont-Names="Arial" Font-Size="8pt" HeaderStyle-BackColor="#cccc99" FooterStyle-BackColor="#cccc99" ItemStyle-BackColor="#ffffff" AlternatingItemStyle-Backcolor="#cccccc" AllowPaging="true" PageSize="20" PagerStyle-Mode="NumericPages" PagerStyle-PageButtonCount="20" OnPageIndexChanged="DataGrid1_PageIndexChanged" AutoGenerateColumns="true" width="450" cellspacing="0" cellpadding="2">
                    <FooterStyle backcolor="#CCCC99"></FooterStyle>
                    <HeaderStyle backcolor="#CCCC99"></HeaderStyle>
                    <PagerStyle pagebuttoncount="20" mode="NumericPages"></PagerStyle>
                    <AlternatingItemStyle backcolor="#CCCCCC"></AlternatingItemStyle>
                    <ItemStyle backcolor="White"></ItemStyle>
                </asp:DataGrid>
            </p>
        </form>
    </body>
    </html>
    chi mi sa dare una mano?

  2. #2
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

  3. #3
    grazie mille...funge.... :mavieni:

  4. #4
    Utente di HTML.it L'avatar di Legnetto
    Registrato dal
    May 2002
    Messaggi
    1,419
    I controlli devi dichiararli così:
    Sotto Inherits

    Protected WithEvents label As System.Web.UI.WebControls.Label

    e così via.
    Altrimenti non li riconosce da codice
    Ciao
    Legnetto

  5. #5
    Utente di HTML.it
    Registrato dal
    Aug 2001
    Messaggi
    1,482
    imports corelab.mysql

    A cosa serve?

    Hey hey, my my Rock and roll can never die!

  6. #6
    è la classe ado.net per poter utilizzare un database mysql...

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.