asp.net datagrid控件的例子,演示了datagrid控件中数据编辑的方法。
代码:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Dim strConnection As String
Dim strSQL As String
Dim objDataSet As New DataSet()
Dim objConnection As OleDbConnection
Dim objAdapter As OleDbDataAdapter
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:Northwind.mdb"
strSQL = "SELECT FirstName, LastName FROM Employees;"
objConnection = New OledbConnection(strConnection)
objAdapter = New OledbDataAdapter(strSQL, objConnection)
objAdapter.Fill(objDataSet, "Employees")
dgNameList1.DataSource = objDataSet.Tables("Employees").DefaultView
dgNameList1.DataBind()
End Sub
</script>
<html>
<body>
<p>在datagrid控件中编辑数据</p>
<table width="100%">
<tr>
<td>Original Data</td>
<td>Data with new Row</td>
<td>Data with edited Row</td>
<td>Data with deleted Row</td>
</tr>
<tr>
<td valign="top"><asp:DataGrid id="dgNameList1" runat="server" /></td>
<td valign="top"><asp:DataGrid id="dgNameList2" runat="server" /></td>
<td valign="top"><asp:DataGrid id="dgNameList3" runat="server" /></td>
<td valign="top"><asp:DataGrid id="dgNameList4" runat="server" /></td>
</tr>
</table>
</body>
</html>