asp.net实例代码之DataGrid数据编辑

发布时间:2019-07-21编辑:脚本学堂
为大家介绍一个asp.net datagrid控件的例子,学习下在datagrid控件中进行数据编辑的方法,有需要的朋友不妨作下参考。

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>