Asp+|datagrid|select| Program | data | Execute------------------C # source program----------------
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.SQL"%>
<script language= "C #" runat= "Server" >
protected void Page_Load (Object Src, EventArgs E)
{
SqlConnection myconnection = new SqlConnection ("server=localhost;uid=sa;pwd=;d atabase=pubs");
Sqldatasetcommand mycommand = new Sqldatasetcommand ("SELECT * from Authors", MyConnection);
DataSet ds = new DataSet ();
Mycommand.filldataset (ds, "Authors");
Mydatagrid.datasource=ds. tables["Authors"]. DefaultView;
Mydatagrid.databind ();
}
</script>
<body>
<asp:datagrid id= "Mydatagrid" runat= "Server"
Width= "700"
Backcolor= "#ccccff"
Bordercolor= "BLACK"
Showfooter= "false"
Cellpadding=3
cellspacing= "0"
Font-name= "Verdana"
Font-size= "8pt"
Headerstyle-backcolor= "#aaaadd"
Maintainstate= "false"
/>
</body>
------------#VB源程序---------------
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.SQL"%>
<script language= "VB" runat= "Server" >
Sub Page_Load (Src as Object, E as EventArgs)
Dim DS as DataSet
Dim MyConnection as SqlConnection
Dim MyCommand as Sqldatasetcommand
MyConnection = New SqlConnection ("server=localhost;uid=sa;pwd=;d atabase=pubs")
mycommand = New Sqldatasetcommand ("SELECT * from Authors", MyConnection)
DS = new DataSet ()
Mycommand.filldataset (ds, "Authors")
Mydatagrid.datasource=ds. Tables ("Authors"). DefaultView
Mydatagrid.databind ()
End Sub
</script>
<body>
<asp:datagrid id= "Mydatagrid" runat= "Server"
Width= "700"
Backcolor= "#ccccff"
Bordercolor= "BLACK"
Showfooter= "false"
Cellpadding=3
cellspacing= "0"
Font-name= "Verdana"
Font-size= "8pt"
Headerstyle-backcolor= "#aaaadd"
Maintainstate= "false"
/>
</body>