ho copiato interamente da asp.net del Apogeo questo esempio:
<%@ Page Language="VB" %>
<%@ import Namespace="SYstem.data" %>
<%@ import Namespace="SYstem.data.oledb" %>
<script runat="server">
dim conn as new oledbconnection( _
"Provider=microsoft.jet.oledb.4.0;" & _
" Data Source =C:\Inetpub\wwwroot\ASP.NET\database\banking.mdb")
sub page_load(obj as object, e as eventargs)
if not page.ispostback then
filldatagrid()
end if
end sub
sub submit(obj as object, e as eventargs)
dim i,j as integer
dim params(7) as string
dim strtext as string
dim blngo as boolean=true
j=0
for i=0 to addpanel.controls.count -1
if addPAnel.controls(i).gettype is _
getType(textbox) then
strtext = ctype(addpanel.controls(i), _
textbox).text
if strtext <> "" then
params(j)=strtext
else
blngo=false
lblMessage.text=lblmessage.text & _
"You forgot to enter a value for" & _
AddPAnel.Controls(i).id & "
"
lblMessage.style("ForeCOlor")="red"
end if
j=j+1
end if
next
if not blngo then
exit sub
end if
dim strSql as string ="Insert into tblUSers " & _
"(FirstName, LastName, Address, CIty, State, " & _
"Zip, Phone) Values(" & _
"'" & params(0) & "'," & _
"'" & params(1) & "'," & _
"'" & params(2) & "'," & _
"'" & params(3) & "'," & _
"'" & params(4) & "'," & _
"'" & params(5) & "'," & _
"'" & params(6) & "')"
ExecuteStatement(strSQL)
FillDataGrid()
end sub
sub dgData_Edit(obj as object, e as datagridCommandEventArgs)
FIllDAtagrid(e.item.itemIndex)
end sub
sub dgData_Delete(obj as object, e as datagridCommandEventArgs)
dim strSQL as string = "DELETE FROM tblUsers " & _
"Where UserID =" & e.item.itemINdex + 1
ExecuteStatement(strSQL)
FIllDAtagrid()
end sub
sub dgData_update(obj as object, e as datagridcommandeventargs)
if UpdateDatastore(e) then
filldatagrid(-1)
end if
end sub
sub dgData_cancel(obj as object, e as datagridcommandeventargs)
filldatagrid(-1)
end sub
sub dgData_pageIndexCHanged(obj as object, e as datagridcommandeventargs)
dgdata.databind()
end sub
function UpdateDatastore(e as datagridcommandeventargs)
dim i,j as integer
dim params(7) as string
dim strtext as string
dim blngo as boolean=true
j=0
for i=1 to e.item.cells.count -3
strtext = ctype(e.item.cells(i).controls(0), _
textbox).text
if strtext <> "" then
params(j)=strtext
j=j+1
else
blngo=false
lblmessage.text=lblmessage.text & _
"you forgot to enter a value
"
end if
next
if not blnGo then
return false
exit function
end if
dim strSQL as string = "UPDATE tblUsers SET " & _
"FirstName = '" & params(0) & "'," & _
"LastName = '" & params(1) & "'," & _
"address = '" & params(2) & "'," & _
"city = '" & params(3) & "'," & _
"state = '" & params(4) & "'," & _
"zip = '" & params(5) & "'," & _
"phone = '" & params(6) & "'," & _
"where userId=" & Ctype (e.Item.Cells(0). _
Controls(1), Label).text
ExecuteStatement(strSQL)
return blnGo
end function
sub filldatagrid(Optional EditIndex as integer=-1)
'apre la connessione
dim objcmd as new oledbCommand _
("select * from tblUsers", Conn)
dim objReader as OleDbDataReader
try
objcmd.connection.open()
objreader=objcmd.ExecuteReader()
catch ex as exception
lblmessage.text ="error grom the database"
end try
dgData.DataSource=objReader
if not editIndex.equals(nothing) then
dgdata.editItemIndex=EditIndex
end if
dgdata.databind()
objreader.close
objcmd.connection.close()
end sub
function executestatement(strSQL)
dim objcmd as new oledbcommand(strSQL, conn )
try
objcmd.connection.open()
objcmd.executenonquery()
catch ex as exception
lblmessage.text="errore"
end try
objcmd.connection.close()
end function
</script>
<html>
<head>
</head>
<body>
<asp:Label id="lblmessage" runat="server"></asp:Label>
<form runat="server">
<ASP.DATAGRID id="dgdata" runat="server" onpageindexchanged="dgdata_PageIndexChanged" bordercolor="black" gridlines="vertical" cellpadding="4" cellspacing="0" width="100%" autogeneratecolumns="false" oneditcommand="dgdata_edit" ondeletecommand="dgdata_delete" oncancelcommand="dgdata_Cancel" onupdatecommand="dgdata_update">
<COLUMNS>
<asp:templateColumn HeaderText="ID">
<ITEMTEMPLATE>
<asp:label id="name" runat="server"></asp:label>
</ITEMTEMPLATE>
</asp:templateColumn>
<asp:BoundColumn headertext="firstName" datafield="firstname"></asp:BoundColumn>
<asp:BoundColumn headertext="lastname" datafield="lastname"></asp:BoundColumn>
<asp:BoundColumn headertext="address" datafield="address"></asp:BoundColumn>
<asp:BoundColumn headertext="city" datafield="city"></asp:BoundColumn>
<asp:BoundColumn headertext="state" datafield="state"></asp:BoundColumn>
<asp:BoundColumn headertext="zip" datafield="zip"></asp:BoundColumn>
<asp:BoundColumn headertext="phone" datafield="phone"></asp:BoundColumn>
<asp:EditCommandColumn HeaderText="edit" EditText="Edit" CancelText="Cancel" UpdateText="Update"></asp:EditCommandColumn>
<asp:ButtonColumn HeaderText="" commandname="delete" text="delete"></asp:ButtonColumn>
</COLUMNS>
</ASP.DATAGRID>
<asp:PAnel id="addPanel" runat="server">
<table>
<tbody>
<tr>
<td valign="top" width="100">
First and Last name:
</td>
<td valign="top" width="300">
<asp:textbox id="tbFname" runat="server"></asp:textbox>
<asp:textbox id="tbLname" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td valign="top">
Address:
</td>
<td valign="top">
<asp:textbox id="tbAddress" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td valign="top">
City, State, Zip:
</td>
<td valign="top">
<asp:textbox id="tbcity" runat="server"></asp:textbox>
,
<asp:textbox id="tbstate" runat="server" size="2"></asp:textbox>
<asp:textbox id="tbzip" runat="server" size="5"></asp:textbox>
</td>
</tr>
<tr>
<td valign="top">
phone:
</td>
<td valign="top">
<asp:textbox id="tbphone" runat="server" size="11"></asp:textbox>
</p>
</td>
</tr>
<tr>
<td align="right" colspan="2" vaign="top">
<asp:button id="btsubmit" onclick="submit" runat="server" text="add"></asp:button>
</td>
</tr>
</tbody>
</table>
</asp:PAnel>
</p>
</form>
</body>
</html>
Ma compare questo errore:'DataSource' is not a member of 'System.Web.UI.HtmlControls.HtmlGenericControl'.
e questo:error BC30456: 'editItemIndex' is not a member of 'System.Web.UI.HtmlControls.HtmlGenericControl'dgd ata.editItemIndex=EditIndex
non riesco a capire il perchè venga fuori questo errore..
ciao