Search This Blog

2010/01/17

Binding to a DataView


(Code View)


Imports System.Data
Partial Class Default2
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
'Binding to DataView
Dim DataTable1 As DataTable
Dim DataRow1 As DataRow

DataTable1 = New DataTable()
DataTable1.Columns.Add(New DataColumn("City", GetType(String)))
DataTable1.Columns.Add(New DataColumn("State", GetType(String)))

Dim strCity(5) As String
Dim strState(5) As String
Dim I As Integer

strCity(0) = "Chicago"
strCity(1) = "Hampstead"
strCity(2) = "Houston"
strCity(3) = "New York"
strCity(4) = "PortLand"

strState(0) = "Illinois"
strState(1) = "New York"
strState(2) = "Texas"
strState(3) = "New York"
strState(4) = "Oregon"

For I = 0 To 4
DataRow1 = DataTable1.NewRow()
DataRow1(0) = strCity(I)
DataRow1(1) = strState(I)
DataTable1.Rows.Add(DataRow1)
Next
GridView1.DataSource = New DataView(DataTable1)
GridView1.DataBind()
End If
End Sub
End Class

(HTML View)

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" Style="left: 74px; position: relative;
top: 68px">
</asp:GridView>
<asp:Label ID="Label1" runat="server" Font-Bold="True" Style="left: 124px; position: relative;
top: -98px" Text="SalesOutLet" Width="93px"></asp:Label></div>
</form>
</body>
</html>

No comments:

Post a Comment