U Have Website We have Cash
If you have website put our banner on it, make money for each visitor
dollarsincome.com

想想

女人一定要有勇气,无论是对爱情也好,对生活也好。如果什么事总是畏首畏尾,那么人生就白白流过了.

导航

动态生成DataTable

Imports System
Imports System.Data
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Partial Class _Default
    Inherits System.Web.UI.Page
    Protected WithEvents myDataTable As DataTable
    Protected WithEvents produces As DataGrid
    Protected WithEvents eventsList As Label

    Protected Sub GridView1_SelectedIndexChanged()
        myDataTable = CType(Cache.Get("myDataTable"), DataTable)

        'if myDataTable is not in the Cache,create it
        If myDataTable Is Nothing Then
            myDataTable = New DataTable("Produces")
            'Build the produce schema
            myDataTable.Columns.Add("ID", Type.GetType("System.Int32"))
            myDataTable.Columns.Add("Name", Type.GetType("System.String"))
            myDataTable.Columns.Add("Category", Type.GetType("System.Int32"))

            'set up the ID column as the PrimaryKey
            Dim pk(1) As DataColumn
            pk(0) = myDataTable.Columns("ID")
            myDataTable.PrimaryKey = pk
            myDataTable.Columns("ID").AutoIncrement = True
            myDataTable.Columns("ID").AutoIncrementSeed = 1
            myDataTable.Columns("ID").ReadOnly = True
            Dim tempRow As DataRow
            Dim i As Int32 = 0
            For i = 1 To 10
                tempRow = myDataTable.NewRow()
                If Math.IEEERemainder(i, 2) = 0 Then
                    tempRow("Name") = "jjj" & i.ToString
                    tempRow("Category") = 1
                Else
                    tempRow("Name") = "dddd" & i.ToString
                    tempRow("Category") = 2
                End If
                myDataTable.Rows.Add(tempRow)
            Next i
            Cache.Insert("myDataTable", myDataTable)


        End If


    End Sub
    Private Sub BindData()
        GridView1_SelectedIndexChanged()
        GridView1.DataSource = myDataTable
        GridView1.DataBind()

    End Sub
End Class

posted on 2006-09-23 23:38  想想  阅读(783)  评论(0编辑  收藏  举报