• Login
  • Our WordPress Plugin
  • Blog Posting Services
  • In Twitter
  • In LinkedIn
J
HARAPHULA
OneStop Shop of Information

Updates

  • 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?
5 5 97
Tricks to Spy on your Friends WhatsApp Messages

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 Rearrange Rows in a Gridview using Drag and Drop?
  • How to update records in a Gridview using Auto…
  • How to add Search Filter in the Column Header of Gridview?
  • Can I fetch B2B Leads Data from LinkedIn to Excel…
  • How to export DataTable to Excel file using VB.NET?
  • 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
  • How to display data from JSON to HTML table using PHP?
  • Database Basics with Terminologies definition for Beginners
  • What is the top Web Scraping Tools for LinkedIn?
  • What are the top LinkedIn Automation Tools for Lead…
  • What is the best Google Maps Scraper for…
  • How Can I use Google Maps for Lead Generation?
  • How to Display JSON Data in a Table using AngularJS?
  • 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…
  • 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

Popular Categories

  • Miscellaneous590
  • Digitalization298
  • Career Guide243
  • Indian Blog207
  • Business Book177
  • Health & Wellness167
  • Travel & Tourism132
  • Your Financial Advisor116
  • Real Estate Consulting111
  • Shopping97
  • Blogging Techniques75
  • Digital Marketing72
  • Home Remedies70
  • SEO Techniques67
  • Programming62
  • Automobiles57
  • Easy Recipes52
  • Fashion & Fantacy52

i20 Sidebar Widgets

How to Choose the right Advertising Design Agency?
How to Choose the right Advertising Design Agency?
Companies face cut-throat competition in the current marketplace. Enterprises must seek to stimulate the brand image that reverberates in the target audience’s consciousness, enabling them...
Interesting SEO Trends likely to influence Digital Marketing in 2018
Interesting SEO Trends likely to influence Digital Marketing in 2022
Digital marketing entails a set of activities carried out in order to make a brand reach the end consumer and retain it too. It is...
Here are the Top 5 Marketing Tools to Consider for your Company
Here are the Top 5 Marketing Tools to Consider for your Company
If you want to run a successful business, there are several crucial factors to consider. These are critical for the growth and enhancement of your...
How Do Virtual Number benefit India Online Services in 2025?
How Do Virtual Number benefit India Online Services in 2025?
In 2025, India’s online landscape continues to evolve rapidly, and businesses are leveraging advanced tools to enhance their operations. One such tool is the virtual...
Design an E-Commerce Website that Converts Visitors into Buyers
How to Design an E-Commerce Website that Converts Visitors into Buyers?
In the age of digitization, an e-com website is not a choice; it is a need. But a website alone? Not even close. In other words, your...
Mistakes to Avoid When Working with a Digital Marketing Agency
Mistakes to Avoid When Working with a Digital Marketing Agency
As digital marketing is a rapidly growing industry, its importance is still not fully understood by many. Thus, small business owners often fall for the...
The Real Impact of Performance-Based SEO on Online Success
The Real Impact of Performance-Based SEO on Online Success
In the ever-evolving digital landscape, businesses are constantly searching for innovative ways to improve their online visibility and drive sustainable growth. Among the many strategies...
8 Advantages of making a Video for promoting your Brand Activities
8 Advantages of making a Video for promoting your Brand Activities
Living in a fast-paced world it is more crucial to find out the modern ways, new techniques to make your products and services stand out...
The rise of Digital Marketing in Healthcare Industry
The rise of Digital Marketing in Healthcare Industry
Healthcare digital marketing leads to the method of advertising your services to healthcare applicants within online stages. Therefore, digital marketing is a profitable investment choice...
Moz or Kiss Metrics like Top 5 Digital Marketing Blogs you Should follow
Moz or Kiss Metrics like Top 5 Digital Marketing Blogs you Should follow
Digital Marketing advances are beyond the capacity of the stop watch. It moves faster than your imagination giving you a tough time in keeping pace...

New Releases

GoDaddy Wordpress Hosting Plans for Freelancers and Bloggers
June 13, 2025

GoDaddy WordPress Hosting Plans for Freelancers and Bloggers

To run a WordPress site efficiently, reliable hosting is essential. GoDaddy, a well-known name in the web hosting industry, offers specialized WordPress hosting plans designed…

Managed Hosting for WordPress and WooCommerce Websites
June 13, 2025
Managed Hosting for WordPress and WooCommerce Websites
Best Cloud Hosting providers NVMe Disk Space, 20 Lakhs Inodes
June 12, 2025
Best Cloud Hosting providers NVMe Disk Space, 20 Lakhs Inodes
Local Hosting for WordPress or Shared Server which is better
June 11, 2025
Local Hosting for WordPress or Shared Server which is better
Comparing AWS Hosting and GoDaddy Web Hosting Features
June 11, 2025
Comparing AWS Hosting and GoDaddy Web Hosting Features
GoDaddy WordPress Hosting Plans: A Comprehensive Overview
June 10, 2025
GoDaddy WordPress Hosting Plans: A Comprehensive Overview
VPS Hosting providers with vCPU Core, TB Bandwidth, NVMe Disk
June 10, 2025
VPS Hosting providers with vCPU Core, TB Bandwidth, NVMe Disk
Best Dedicated Server Hosting for Blog Website and Bloggers
June 10, 2025
Best Dedicated Server Hosting for Blog Website and Bloggers
Fastest Web Hosting for Small and Medium Size Businesses
June 10, 2025
Fastest Web Hosting for Small and Medium Size Businesses
Best Cloud Hosting providers for Small Scale Businesses
June 10, 2025
Best Cloud Hosting providers for Small Scale Businesses
Best Cloud Server Hosting Services for Personal Use or Reselling
June 10, 2025
Best Cloud Server Hosting Services for Personal Use or Reselling
Good Hosting Plans for your Personal Portfolio or Blogs
June 10, 2025
Good Ecommerce Hosting for your Personal Portfolio or Blogs
Ecommerce Website Hosting for Small Business and NGOs
June 10, 2025
Ecommerce Website Hosting for Small Business and NGOs
Best and Cheapest Reseller Hosting for WordPress Freelancers
June 10, 2025
Best and Cheapest Reseller Hosting for WordPress Freelancers
Cheapest Dedicated Server Hosting for Entrepreneurs and Enterprises
June 10, 2025
Cheapest Dedicated Server Hosting for Entrepreneurs and Enterprises
Best Web Hosting for Beginners to Host their WordPress Blog
June 10, 2025
Best Web Hosting for Beginners to Host their WordPress Blog
Best Web Hosting for Small Businesses Cost-Effective Solutions
June 10, 2025
Best Web Hosting for Small Businesses Cost-Effective Solutions
WordPress Migration? Time to Choose Hosting Provider wisely
June 9, 2025
WordPress Migration? Time to Choose Hosting Provider wisely
explore us...

OUR FACILITIES

  • 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