<%@ Page Language="VB" %> <%@ import Namespace="System.Data" %> <script runat="server">
Dim dtblCart As DataTable Dim dcolColumn As DataColumn Dim dvwCart As DataView Sub Page_Load ' Create DataTable dtblCart = New DataTable( "Cart" ) Dim drowItem As DataRow ' Create Columns dcolColumn = New DataColumn( "ProductID", GetType( Int32 ) ) dtblCart.Columns.Add( dcolColumn ) dcolColumn = New DataColumn( "ProductName", GetType( String ) ) dtblCart.Columns.Add( dcolColumn ) dcolColumn = New DataColumn( "ProductCategory", GetType( String ) ) dtblCart.Columns.Add( dcolColumn ) dcolColumn = New DataColumn( "ProductPrice", GetType( Decimal ) ) dtblCart.Columns.Add( dcolColumn ) End SUb Sub Add(s As object,e As EventArgs) Dim drowItem As DataRow drowItem = dtblCart.NewRow() drowItem(0) = 0 drowItem(1) = 1 drowItem(2) = 2 drowItem(3) = 3 dtblCart.Rows.Add(drowItem) dvwCart = dtblCart.Defaultview dgrdCart.DataSource = dvwCart dgrdCart.DataBind() End Sub
Sub AddOther(s As object,e As EventArgs) drowItem = dtblCart.NewRow() drowItem(0) = "11" drowItem(1) = "c" drowItem(2) = "v" drowItem(3) = "22" dtblCart.Rows.Add(drowItem) dvwCart = dtblCart.Defaultview dgrdCart.DataSource = dvwCart dgrdCart.DataBind() End Sub </script> <html> <head> </head> <body> <form runat="server"> <asp:DataGrid id="dgrdCart" Runat="Server"></asp:DataGrid> <asp:linkButton id="btnAdd" onclick="Add" Runat="Server" Text="Add"/> <asp:LinkButton id = "btnAddOther" OnClick = "AddOther" Runat = "Server" Text = "AddOther"/> </form> </body> </html> 请指点一下!谢谢!