数据绑定到两个不同的datagrid控件(vb.net)

发布时间:2020-08-09编辑:脚本学堂
学习vb.net的例子,实现数据同时绑定到两个不同的datagrid控件中,有需要的朋友作个参考。

在vb.net中实现绑定数据到两个不同的datagrid控件中。
代码:
 

复制代码 代码示例:
<%@ page language=vb debug=true %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.oledb" %>
<script runat=server>
sub page_load(byval sender as object, byval e as eventargs)
    dim dbconn as oledbconnection
    dim dbcommand as oledbdataadapter
    dim dspagedata as new dataset
    dbconn = new oledbconnection( _
        "provider=microsoft.jet.oledb.4.0;" _
        & "data source=" _
        & server.mappath("employeedatabase.mdb;"))
    dbcommand = new oledbdataadapter _
        ("select * from employee", dbconn)
    dbcommand.fill(dspagedata, _
        "employeeall")
    dbcommand = new oledbdataadapter _
        ("select lastname " _
        & " from employee", dbconn)
    dbcommand.fill(dspagedata, _
        "employees")
    dgemps1.datasource = _
        dspagedata.tables("employeeall").defaultview
    dgemps1.databind()
    dgemps2.datasource = _
        dspagedata.tables("employees").defaultview
    dgemps2.databind()
end sub
</script>
<html>
<head>
<title>在datagrid control中显示访问数据--www.jb200.com</title>
</head>
<body leftmargin="40">
<form runat="server">
<br><br>
<asp:datagrid
    id="dgemps1"
    runat="server"
    autogeneratecolumns="true"
>
</asp:datagrid>
<br><br>
<asp:datagrid
    id="dgemps2"
    runat="server"
    autogeneratecolumns="true"
>
</asp:datagrid>
</form>
</body>
</html>