ASPX有这种写法么?你这是ASP的写法。
看下面这个例子:
<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
' TODO: Update the ConnectionString and CommandText values for your application
if not IsPostBack then
Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:/Source/devnet/DevDB.mdb;Persist Security Info=False"
Dim CommandText As String = "select * from publicinfo where infotype=0 order by postdate"
Dim myConnection As New OleDbConnection(ConnectionString)
Dim myCommand As New OleDbCommand(CommandText, myConnection)
myConnection.Open()
DataGrid1.DataSource = myCommand.ExecuteReader()
DataGrid1.DataBind()
end if
End Sub
Sub Grid_ItemClick(Sender As Object, E As DataGridCommandEventArgs)
dim recid as string
if E.CommandSource.CommandName = "Del" then
recid = E.Item.Cells(0).Text
Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:/Source/devnet/DevDB.mdb;Persist Security Info=False"
Dim CommandText As String = "delete from publicinfo where id=" &
recid
Dim myConnection As New OleDbConnection(ConnectionString)
Dim myCommand As New OleDbCommand(CommandText, myConnection)
myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.CommandText = "select * from publicinfo where infotype=0"
DataGrid1.DataSource = myCommand.ExecuteReader()
datagrid1.DataBind
else
end if
End Sub
</script>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
<h2>新闻-News
</h2>
<hr size="1" />
<form runat="server">
<asp:datagrid id="DataGrid1" runat="server" OnItemCommand="Grid_ItemClick" BorderColor="#3366CC" BorderWidth="1px" BorderStyle="None" PageSize="3" AutoGenerateColumns="False" AllowPaging="false" CellPadding="4" BackColor="White" Width="90%">
<FooterStyle forecolor="#003399" backcolor="#99CCCC"></FooterStyle>
<HeaderStyle font-bold="True" forecolor="#CCCCFF" backcolor="#003399"></HeaderStyle>
<PagerStyle horizontalalign="Left" forecolor="#003399" backcolor="#99CCCC" mode="NumericPages"></PagerStyle>
<SelectedItemStyle font-bold="True" forecolor="#CCFF99" backcolor="#009999"></SelectedItemStyle>
<ItemStyle forecolor="#003399" backcolor="White"></ItemStyle>
<Columns>
<asp:BoundColumn DataField="id" HeaderText="编号"></asp:BoundColumn>
<asp:BoundColumn DataField="infotitle" HeaderText="新闻标题"></asp:BoundColumn>
<asp:ButtonColumn Text="查看" HeaderText="查看" CommandName="View"></asp:ButtonColumn>
<asp:ButtonColumn Text="删除" HeaderText="删除" CommandName="Del"></asp:ButtonColumn>
</Columns>
</asp:datagrid>
<br />
<br />
<asp:Button id="Button1" runat="server" Text="添加新闻"></asp:Button>
</form>
</body>
</html>