Business Premium email | AI Website Builder | KVM 2 VPS Hosting
Cheaper Cloud Hosting | Business Web Hosting
  • Register
  • Login
  • Our WordPress Plugin
  • Blog Posting Services
  • In Twitter
  • In LinkedIn
J
HARAPHULA
OneStop Shop of Information

Updates

  • The best Guest Posting Website to boost your Online Presence
    •
  • Why Web2 Guest Posts Backlinks matters for Google Ranking?
    •
  • How Paid Guest Posting Services Help for SEO Backlinks?
    •
  • Why Guest Posting is a best approach to boost Products Sales?
    •
  • Do-follow links from Guest Posting how affecting Ranking
    •
  • Free Guest Posting in LinkedIn or Medium Accelerate Indexing
    •
  • Should I go for paid Guest Posting with No-follow links?
    •
  • Tricks for Lead Generation using Guest Posting deep links
    •
  • How Guest Posting Services useful for SEO Backlinks & Ranking?
    •
  • Why I will Choose Link Insertion in place of fresh Guest Posting with link?
    •
  • Quality Backlinks or Lead Generation when to use Guest Posting Service?
    •

How to display Excel File records in an ASP.NET Gridview?

Microsoft Technologies
December 7, 2016
3.7 (3 votes)
How to display Excel File records in an ASP.NET Gridview? How to display Excel File records in an ASP.NET Gridview?
3 5 97
FREE Signup | Drive Leads use the Power of Article Marketing

Due to the popularity of MS Excel, Still today more than 75% of Organizations prefers to maintain their data in MS-Excel. Whether it’s the matter of project management or a budget plan, MS-Excel is an awesome tool. I noticed in my organization more then 80% percent records are in Excel. One day my boss come to me with a plan that he need to update “Utilization_Reports.xlsx” using User Interface. For him I had taken the ownership to develop this tool. During this development phases I found how to fetch data from an Excel File like a database table using SQL Queries. This stay interesting for me. Sharing the same for your reference.

Gridview

<asp:GridView ID="grdRecords" runat="server" AutoGenerateColumns="false" AllowPaging="true" PageSize="10" Font-Names="Arial" Font-Size="11pt" AlternatingRowStyle-BackColor="#C2D69B" HeaderStyle-BackColor="green" HeaderStyle-ForeColor="#FFFFFF" OnPageIndexChanging="OnPaging" AutoGenerateEditButton="true" Width="100%">
<Columns>
<asp:TemplateField  HeaderText="Employee Name" SortExpression="Name">
<ItemTemplate>
<asp:Label ID="lblEmpName" runat="server" Text='<%# Bind("Name")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Employee ID" SortExpression="ID">
<ItemTemplate>
<asp:Label ID="lblEmpID" runat="server" Text='<%# Bind("ID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Status:
<asp:DropDownList ID="ddlStatus" runat="server" OnSelectedIndexChanged="CountryChanged" AutoPostBack="true" AppendDataBoundItems="true">
<asp:ListItem Text = "ALL" Value = "ALL"></asp:ListItem>
</asp:DropDownList>
</HeaderTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlRowStatus" runat="server" AutoPostBack="true">
<asp:ListItem>thisis</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<%# Eval("Status") %>
</ItemTemplate>
</asp:TemplateField>                    
</Columns>
</asp:GridView>

As we mentioned above here I want to fetch an excel file like a database table. So first let us declare the connection string for MS-Excel. That’s what I did in below web.config file.

Web.Config

<appSettings>
<add key="FolderPath" value="Files/"/>
</appSettings>
<connectionStrings>
<!--<add name ="Excel03ConString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}; Extended Properties='Excel 8.0'" />-->
<add name ="ConnString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties='Excel 8.0'"/>
</connectionStrings>

To bind data to the Gridview in Codebehind I am with the below Subroutine. In BindGrid I am passing FilePath and File Extention as the parameters. These are simple string varibales. Declare as global variables. To fetch data from Excel like a database First I am traking the 0th Sheet of Excel. Then running a SQL Query over the table of my Excel File. Finally using a ASP.NET DataAdapter I am filling data to the gridview.

BindGrid

Private Sub BindGrid(ByVal FilePath As String, ByVal Extension As String)

ConStr = String.Format(ConStr, FilePath)

Dim connExcel As New OleDbConnection(ConStr)
Dim cmdExcel As New OleDbCommand()
Dim oda As New OleDbDataAdapter()
Dim dtbl As New DataTable()

cmdExcel.Connection = connExcel

'Get the name of First Sheet 
connExcel.Open()

Dim dtExcelSchema As DataTable
dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
Dim SheetName As String = dtExcelSchema.Rows(0)("TABLE_NAME").ToString()

connExcel.Close()

'Read Data from First Sheet 
connExcel.Open()

If ViewState("Filter").ToString() = "ALL" Then
cmdExcel.CommandText = "SELECT * From [" &amp; SheetName &amp; "]"
Else
cmdExcel.CommandText = "SELECT * From [" &amp; SheetName &amp; "] WHERE Status='" &amp; ViewState("Filter").ToString() &amp; "'"
End If

oda.SelectCommand = cmdExcel
oda.Fill(dtbl)
connExcel.Close()

'Bind Data to GridView 
grdRecords.DataSource = dtbl
grdRecords.DataBind()

End Sub

The above subroutine is responsible to Fill the Gridview. But to display data in Gridview we need to Call this during page load. That’s what I am doing in below. Inside the not page.ispostback event I am calling the Function with required parameters.

In Page Load

Dim FilePath as String = "C:/demo.xlsx"
Dim Extension as String = ".xlsx"

If Not Page.IsPostBack Then
ViewState("Filter") = "ALL"
BindGrid(FilePath, Extension)
End If

Tags:ASP.NET Gridview, ASP.NET Gridview Example, Display Excel File records, MS-Excel like Table, Page.IsPostBack, Records in an ASP.NET Gridview
How to add Search Filter in the Column Header of Gridview?
Causes and Symptoms of Miscarriage – Tips for Safe Pregnancy

Related Posts

  • How to Export data from MySQL to Excel using PHP?
  • How to export Data from SQL tables to a Excel file…
  • How to update records in a Gridview using Auto…
  • How to Rearrange Rows in a Gridview using Drag and Drop?
  • How to add Search Filter in the Column Header of Gridview?
  • How to export DataTable to Excel file using VB.NET?
  • Can I fetch B2B Leads Data from LinkedIn to Excel…
  • Using XMLHttpRequest How to Bind Data from XML to…
  • Top LinkedIn Scraping Tools to fetch Clients Data…
  • Tool to unzip tar file in Windows Operating System? - 7-Zip
  • How Can I fetch Phone Numbers from 1000's of Websites?
  • Is there any Email Extractor to find Emails from Websites?
  • Top B2B Lead Generation Tools to Grow B2B Leads from…
  • How to Design a Database? - Database Design for Beginners
  • What is the top Web Scraping Tools for LinkedIn?
  • What are the top LinkedIn Automation Tools for Lead…
  • How to display data from JSON to HTML table using PHP?
  • What is the best Google Maps Scraper for…
  • How to Display JSON Data in a Table using AngularJS?
  • How Can I use Google Maps for Lead Generation?
  • JSON Tutorial for beginners - Learn JSON with Examples
  • How to read JSON file data in JQuery? - GetJSON Example
  • What are Some Affordable Data Extraction Tools for…
  • Database Basics with Terminologies definition for Beginners
  • What is the best Email Scraper Tool for LinkedIn?
On-page SEO booster,
Google Friendly,
XML based
PHP/WP Sidebar
FREE Widgets
demo

Our Web2 Blogs

Business Hosting Provider
Hosting Shop
Hosting for WordPress Bloggers
Publishing Services
Indian Blog
Blog Posting Services

KVM 8
Cloud Enterprise
AI Website Builder
Business email

Popular Categories

  • Miscellaneous589
  • Digitalization298
  • Career Guide244
  • Indian Blog207
  • Business Book178
  • Health & Wellness168
  • Travel & Tourism132
  • Your Financial Advisor120
  • Real Estate Consulting111
  • Shopping97
  • Digital Marketing78
  • Blogging Techniques78
  • Home Remedies70
  • SEO Techniques67
  • Programming62
  • Automobiles57
Cloud Startup
KVM 2
Starter email
AI Website Builder

i20 Sidebar Widgets

New Releases

Discover the best Business Meeting Venues for Productive Corporate Gatherings
July 11, 2025

Discover the best Business Meeting Venues for Productive Corporate Gatherings

In today’s dynamic corporate world, business meeting venues play a vital role in setting the tone for productive collaboration, strategic discussions, and professional networking. Whether…

YouTube Advertising Advantages, Limitations and best Practices
July 7, 2025
YouTube Advertising Advantages, Limitations and best Practices
b2b Email Marketing jobs and ZOHO Campaigns for professionals
July 7, 2025
b2b Email Marketing jobs and ZOHO Campaigns for professionals
YouTube Marketing Techniques to minimize Advertising Costs
July 2, 2025
YouTube Marketing Techniques to minimize Advertising Costs
Natural Hair Plantation for Women of any Age no Surgery
July 1, 2025
Natural Hair Plantation for Women of any Age with no Surgery
Eyeliner for Hooded Eyes to apply before applying Eyeshadow
July 1, 2025
Eyeliner for Hooded Eyes to apply before applying Eyeshadow
Comparing Paid and Free Website Builder for Small Business
July 1, 2025
Comparing Paid and Free Website Builder for Small Business
Google Search Console for SEO Tools for every Webmaster
July 1, 2025
Google Search Console for SEO Tools for every Webmaster
Digital Marketing Guest Post best practices to boost Sales
July 1, 2025
Digital Marketing Guest Post best practices to boost Sales
Deep Stretch Marks on Thighs and Belly during Pregnancy
June 26, 2025
Deep Stretch Marks on Thighs and Belly areas during Pregnancy
Fade Pregnancy Stretch Marks appear as Streaks or Lines on the Skin
June 26, 2025
Fade Pregnancy Stretch Marks appear as Streaks or Lines on the Skin
The best Guest Posting Website to boost your Online Presence
June 26, 2025
The best Guest Posting Website to boost your Online Presence
Digital Marketing Firms for Startup WordPress Blogs
June 25, 2025
Hi-Tech Digital Marketing Firms for Startup WordPress Blogs
Best Foods and 7 Day Diet Plan for Weight Loss help for Housewives
June 25, 2025
Prescribed Best Foods with 7 Day Diet Plan for Weight Loss Journey
Advanced Stage 3 Breast Cancer in Men and Women
June 25, 2025
Advanced Stage 3 Breast Cancer in Men and Women but Treatable
Explain Digital Marketing to Content Marketers for Leads
June 25, 2025
Explain Digital Marketing to Content Marketers for Sales Leads
Best Digital Marketing Agencies to boost AdSense Earning
June 24, 2025
Best Digital Marketing Agencies to boost AdSense Earning
Termites in House? Pest Control Services to Save Damage
June 24, 2025
Termites in House? Pest Control Services to Save Damage
explore us...
Cloud Startup | Premium Web Hosting | KVM 8 | Premium Website Builder | Business Starter email

OUR FACILITIES

  • Register
  • Login
  • Our Background
  • Privacy
  • WordPress.org

CONTACT INFO

  • Do WhatsApp
  • Reach us

SEO GUEST POSTING

Do you like to publish your Stories near Quality Audiences? If so, “OneStop Shop” is the best platform for you. We are one among the vastly growing Indian Blog. Reach us to publish your Stories with lifelong No-Follow links.

WHY ONESTOP?

We are here to bring high Quality Information. As a multi-niche platform we have spend several years for Collecting various useful Stories. Dream to establish a domain where from you can get all your day today required information. We covers Animals to Zoology.
©2014-2025 JHARAPHULA, ALL RIGHTS RESERVED.
Show Buttons