<%@ Page Language="VB" EnableViewState="false" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Microsoft .NET Excel to Multiple DataGrid Sample Using VB.NET and Microsoft Excel Compatible Spreadsheet Component for Microsoft .NET, ASP.NET, C#, VB.NET, XLS and Microsoft Visual Studio .NET</title>
<meta content="Microsoft .NET Excel to Multiple DataGrid sample using Visual Basic .NET and SpreadsheetGear 2010, a royalty free Microsoft Excel compatible spreadsheet component for the Microsoft .NET Framework featuring the fastest and most complete calculation engine available. Create, read, modify, calculate and write Microsoft Excel workbooks from your Microsoft .NET, ASP.NET, C#, VB.NET and Microsoft Office solutions. Integrates with Microsoft Visual Studio .NET, including IntelliSense and Dynamic Help." name="description" />
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
' Create a workbook from an Excel file
Dim ssFile As String = Server.MapPath("files/spicenorth.xls")
Dim workbook As SpreadsheetGear.IWorkbook = SpreadsheetGear.Factory.GetWorkbook(ssFile)
' Get a DataSet for the entire workbook. This creates a default
' DataSet with one DataTable created for each worksheet using
' the "UsedRange" area of the worksheet. An optional way of doing this
' is to pass a string containing one or more references which may be
' defined names. Each reference is used to create a DataTable.
'
' Optional Example:
' Dim dataSet As DataSet = workbook.GetDataSet(
' "YearSales,Q1Sales,Q2Sales,Q3Sales,Q4Sales",
' SpreadsheetGear.Data.GetDataFlags.FormattedText)
'
Dim dataSet As DataSet = workbook.GetDataSet(SpreadsheetGear.Data.GetDataFlags.FormattedText)
' Call the BindToGrid helper method for each DataGrid
BindToGrid(DataGridYear, dataSet, "Year Sales")
BindToGrid(DataGridQ1, dataSet, "Q1 Sales")
BindToGrid(DataGridQ2, dataSet, "Q2 Sales")
BindToGrid(DataGridQ3, dataSet, "Q3 Sales")
BindToGrid(DataGridQ4, dataSet, "Q4 Sales")
End Sub 'Page_Load
Sub BindToGrid(dataGrid As DataGrid, dataSet As DataSet, dataMember As String)
dataGrid.DataSource = dataSet
dataGrid.DataMember = dataMember
dataGrid.DataBind()
End Sub 'BindToGrid
</script>
<style type="text/css">
.headerStyle
{
background-color: #FF6600;
color: #FFFFFF;
font-size: 8pt;
font-weight: bold;
}
.itemStyle
{
background-color: #FFFFEE;
color: #000000;
font-size: 8pt;
}
.alternateItemStyle
{
background-color: #FFFFFF;
color: #000000;
font-size: 8pt;
}
</style>
</head>
<body style="font-family: Verdana;">
<h5>Microsoft .NET Excel to Multiple DataGrid Sample using<br />Visual Basic .NET and <a href="http://www.spreadsheetgear.com/products/spreadsheetgear.net.aspx">SpreadsheetGear 2010</a></h5>
<form id="form1" runat="server">
<table style="font-family: Verdana; font-size: 12px">
<tr>
<td>Total Sales for Year</td>
</tr>
<tr>
<td><ASP:DataGrid ID="DataGridYear" BorderWidth="1px" BorderColor="#AAAAAA" CellPadding="4" runat="server">
<HeaderStyle CssClass="headerStyle"/>
<ItemStyle CssClass="itemStyle"/>
<AlternatingItemStyle CssClass="alternateItemStyle"/>
</ASP:DataGrid>
</td>
</tr>
<tr>
<td><br />Q1 Sales</td>
</tr>
<tr>
<td><ASP:DataGrid ID="DataGridQ1" BorderWidth="1px" BorderColor="#AAAAAA" CellPadding="4" runat="server">
<HeaderStyle CssClass="headerStyle"/>
<ItemStyle CssClass="itemStyle"/>
<AlternatingItemStyle CssClass="alternateItemStyle"/>
</ASP:DataGrid>
</td>
</tr>
<tr>
<td><br />Q2 Sales</td>
</tr>
<tr>
<td><ASP:DataGrid ID="DataGridQ2" BorderWidth="1px" BorderColor="#AAAAAA" CellPadding="4" runat="server">
<HeaderStyle CssClass="headerStyle"/>
<ItemStyle CssClass="itemStyle"/>
<AlternatingItemStyle CssClass="alternateItemStyle"/>
</ASP:DataGrid>
</td>
</tr>
<tr>
<td><br />Q3 Sales</td>
</tr>
<tr>
<td><ASP:DataGrid ID="DataGridQ3" BorderWidth="1px" BorderColor="#AAAAAA" CellPadding="4" runat="server">
<HeaderStyle CssClass="headerStyle"/>
<ItemStyle CssClass="itemStyle"/>
<AlternatingItemStyle CssClass="alternateItemStyle"/>
</ASP:DataGrid>
</td>
</tr>
<tr>
<td><br />Q4 Sales</td>
</tr>
<tr>
<td><ASP:DataGrid ID="DataGridQ4" BorderWidth="1px" BorderColor="#AAAAAA" CellPadding="4" runat="server">
<HeaderStyle CssClass="headerStyle"/>
<ItemStyle CssClass="itemStyle"/>
<AlternatingItemStyle CssClass="alternateItemStyle"/>
</ASP:DataGrid>
</td>
</tr>
</table>
</form>
<h6>Copyright 2005 © SpreadsheetGear LLC. All Rights Reserved.<br /><a href="http://www.spreadsheetgear.com">www.spreadsheetgear.com</a></h6>
</body>
</html>