<asp:GridView ID="GridView1" OnRowEditing="GridView1_RowEditing" OnUpdateCommand="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting" runat="server" CssClass="fixedColWidth" CellPadding="0" ForeColor="#333333" Height="273px"> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <Columns> <asp:CommandField ShowEditButton="True" /> </Columns> <EditRowStyle BackColor="#999999" /> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#F7F6F3" ForeColor="#333333"/> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#E9E7E2" /> <SortedAscendingHeaderStyle BackColor="#506C8C" /> <SortedDescendingCellStyle BackColor="#FFFDF8" /> <SortedDescendingHeaderStyle BackColor="#6F8DAE" /> </asp:GridView>
Public Class WebForm1 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'Load Excel File on Page Load loadExcel() End Sub Public Function loadExcel() 'loadExcel Function to show the file to the gridView. Dim MyConnection As System.Data.OleDb.OleDbConnection Dim DtSet As System.Data.DataSet Dim MyCommand As System.Data.OleDb.OleDbDataAdapter Dim filePath = Path.Combine(GlobalVariable.savedPath, GlobalVariable.excelFileName) 'Dim filePath = "C:\excelfiles\Book11.xlsx" 'Code to Use an Oledb Connection to get data from the Excel File MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & filePath & ";Extended Properties='Excel 12.0 Xml;HDR=YES;';") 'Code to Read the Sheet Selected from the Excel Spread Sheet' MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection) '-- Extra Code Not Needed which Maps the tables as Columns from the Spreadsheet 'MyCommand.TableMappings.Add("Table", "Net-informations.com") DtSet = New System.Data.DataSet MyCommand.Fill(DtSet) 'Populates GridView with the excel Spreadsheet GridView1.DataSource = DtSet.Tables(0) 'Code Below needed to show the excel to GridView GridView1.DataBind() MyConnection.Close() Return Nothing End Function End Class
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)