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?