Sunday, January 17, 2010

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)
GridView1.DataSource = New DataView(DataTable1)
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" "">

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

No comments:

Post a Comment