• Our Services
  • Press Releases
  • Hosting Hub
  • Sitemap
  • Login
  • Our WordPress Plugin
  • Blog Posting Services
  • In Twitter
  • In LinkedIn
  • Our Code Repository
J
HARAPHULA
OneStop Shop of Information

Updates

  • Termites in House? Pest Control Services to Save Damage
    •
  • How to Buy Facebook Likes and boost your Reach?
    •
  • CNC Machining in Model Making Dubai for Prototypes
    •
  • Human Behavior in Men and Women Aged 18 to 35
    •
  • Best Nutrition for Active Working Dogs
    •
  • Why Homeowners Love Brown Granite Worktops for their Kitchens?
    •
  • Siding Repair in Cleveland – Why Timely Maintenance is Crucial for your Home?
    •
  • How to Transition to Toxic-Free Sanitary Pads Smoothly?
    •
  • Potassium Feldspar – A Comprehensive Guide
    •
  • What are Textile Chemicals and Why are they Important?
    •
  • How to Detect and Repair Leaks in PPRC Pipes and Fittings?
    •
  • Plumber Islington – MK Plumbers – Your Local Plumbing Experts
    •
  • Top Storage Sheds in Corowa – Reliable and Affordable Options
    •
  • Mastering Pest Control – Learn Online for a Sustainable Future
    •
  • Effective Strategies for Pest Control in Urban Environments
    •

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 88

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

Popular Categories

  • Miscellaneous589
  • Digitalization298
  • Career Guide244
  • Indian Blog207
  • Business Book177
  • Health & Wellness168
  • Travel & Tourism132
  • Your Financial Advisor120
  • Real Estate Consulting111
  • Shopping97
  • Digital Marketing78
  • Blogging Techniques78
  • Home Remedies70
  • SEO Techniques67
  • Programming62
  • Automobiles57
  • Fashion & Fantacy53
  • Easy Recipes52

Our Popular Links

BootStrap Dropdown list with Checkbox Selected values will Show
Cheapest Cloud Hosting Services for Node.js Applications
How to keep Mashed Potatoes Warm all Dinner Long?
List of Linux Website Hosting Companies
Cheapest Hosting Plans for Joomla Blogs
Linux, PHP, MySQL Hosting Solutions for Freelancers
Hosting Plans for Large Enterprise Websites
Vitamin K Is the Ingredient Said to Fade Dark Circles – Does it Work?
Hosting Limitations for Shared Servers
Why I will Choose VPS Hosting for Game Applications?
SSD Storage Hosting Services with High-Speed MySQL Servers
40 lifelong SEO backlinks (tire 1 + tire 2)
Google friendly multi-niche Blog accepting Guest Posting
Page Speed Optimization Services with FCP, LCP, CLS or image Optimization

i20 Sidebar Widgets

How to Enroll in Graphic Designing Course in Lahore?
How to Enroll in Graphic Designing Course in Lahore?
Graphic designing is a pivotal skill in today’s digital world, blending creativity and technology to produce compelling visuals. This field has gained immense popularity in...
YouTube Marketing Techniques to minimize Advertising Costs
YouTube Marketing Techniques to minimize Advertising Costs
In today’s digital landscape, YouTube stands as one of the most powerful platforms for marketing, offering unparalleled reach and engagement opportunities. With over 2.7 billion...
Social Media Monetization - Where Can you Earn more?
Social Media Monetization – Where Can you Earn more?
Social media platforms have become one of the most significant sources of income for creators, influencers, and businesses alike. As these platforms continue to evolve,...
Digital Marketing Strategies for Small Businesses
Digital Marketing Strategies for Small Businesses
For any small business, formulating digital marketing strategies is a crucial step. But this can be difficult because many small business owners are not sure...
The Future of Digital Marketing - Trends to Watch
The Future of Digital Marketing – Trends to Watch
The digital marketing landscape is constantly evolving, and it’s crucial for businesses to stay ahead of the game. As technology advances and consumer behavior changes,...
Top SEO Company in Delhi NCR to enhance your Online Presence
Top SEO Company in Delhi NCR to enhance your Online Presence
Today’s digital world requires having a strong online presence for businesses to succeed in the fast-paced market. Search Engine Optimization (SEO) plays a vital role...

Our Web2 Blogs

Home Remedies
SEO Guest Posting
Digital Marketing
Learn Digital Marketing
Guest Posting Services
Blog for Bloggers
SEO Blog
Blog for Tourism

New Releases

YouTube Advertising Advantages, Limitations and best Practices
July 12, 2025

YouTube Advertising Advantages, Limitations and best Practices

YouTube has become one of the most influential digital platforms for advertising, offering businesses a dynamic way to reach global audiences. With billions of users…

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
ICICI Bank Vehicle Loan for newly Opened Transportation Agencies
June 24, 2025
ICICI Bank Vehicle Loan for newly Opened Transportation Agencies
explore us...

Our Facebook Groups

Paid Guest Posting Services with lifelong Links

SEO Backlinks, Guest Posting, Link Insertion plus Link Exchange hub

Instant Guest Posting Services with lifelong Do-Follow links

Guest Posting SEO Services with High DA aged Domains

Free or Paid Guest Posting Service in India | UK | USA

Free Guest Posting, Link exchange, SEO, SEM, PBN links, web2 links

Cheap Guest Posting Services with high Authority Blogs

OUR FACILITIES

  • Login
  • Our Background
  • Privacy
  • WordPress.org

CONTACT INFO

  • Reach us
  • WhatsApp 919096266548

OUR SERVICES

  • Blog Posting Opportunity
  • *.fig, *.psd 2 html
  • Video Ads Designing
  • Setup your WordPress Blog
  • Optimizing Google PageSpeed
  • b2b Gmail IDs

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.