Sub Page_Load(sender As Object, e As EventArgs) If Not IsPostBack Then Dim values as ArrayList= new ArrayList() values.Add ( "IN") values.Add ( "KS") values.Add ( "MD") values.Add ( "MI") values.Add ( "OR") values.Add ( "TN") DropDown1.DataSource = values DropDown1.DataBind End If End Sub |
Sub Page_Load(sender As Object, e As EventArgs) If Not IsPostBack Then Dim dt As DataTable Dim dr As DataRow Dim i As Integer ''建立DataTable dt = New DataTable dt.Columns.Add(New DataColumn( "IntegerValue", GetType(Integer))) dt.Columns.Add(New DataColumn( "StringValue", GetType(String))) dt.Columns.Add(New DataColumn( "DateTimeValue", GetType(DateTime))) dt.Columns.Add(New DataColumn( "BooleanValue", GetType(Boolean))) ''填充一些数据 For i = 1 To 9 dr = dt.NewRow() dr(0) = i dr(1) = "Item " + i.ToString() dr(2) = DateTime.Now.ToShortTimeString If (i Mod 2 <> 0) Then dr(3) = True Else dr(3) = False End If ''把数据行添加到表 dt.Rows.Add(dr) Next GridView1.DataSource = New DataView(dt) GridView1.DataBind() End If End Sub |
Sub Page_Load(sender As Object, e As EventArgs) If Not IsPostBack Then Dim h As Hashtable = new Hashtable() h.Add ( "key1", "value1") h.Add ( "key2", "value2") h.Add ( "key3", "value3") MyDataList.DataSource = h MyDataList.DataBind End If End Sub |
Sub Page_Load(sender As Object, e As EventArgs) If Not IsPostBack Then Dim values as ArrayList= new ArrayList() values.Add (0) values.Add (1) values.Add (2) values.Add (3) values.Add (4) values.Add (5) values.Add (6) DataList1.DataSource = values DataList1.DataBind End If End Sub Function EvenOrOdd(number As Integer) As String If (number Mod 2 <> 0) Then Return "Odd" Else Return "Even" End If End Function <asp:DataList id="DataList1" ……> <ItemTemplate> Number Value: <%# Container.DataItem %> Even/Odd: <%# EvenOrOdd(Container.DataItem) %> </ItemTemplate> </asp:DataList> |