• 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?
5 5 78

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

  • List of frequently used common SQL Queries with Example
  • Microsoft ASP.NET Interview Questions with Answers
  • How to update records in a Gridview using Auto…
  • How to implement Paging and Sorting in ASP.NET…
  • Example of Resume for IT professionals to get their…
  • ASP.NET Login form Example validating user from SQL…
  • How to display various Files icon images in Datagrid rows?
  • ADO.NET ExecuteNonQuery, ExecuteReader,…
  • PHP Treeview Example using data from MySQL Database
  • How to add Search Filter in the Column Header of Gridview?
  • Database Basics with Terminologies definition for Beginners
  • Using LocalStorage Objects vs Web SQL Database in HTML5
  • How to Design a Database? - Database Design for Beginners
  • How to Rearrange Rows in a Gridview using Drag and Drop?
  • SQL Server Interview Questions for DBA professionals
  • On Mouseover how to Highlight ASP.NET Gridview Selected Row
  • In a dynamic ASP.NET Gridview Delete row example
  • User Interface (UI) Design Strategies using SDLC Lifecycle
  • Why you Should Spend more Time Thinking related to…
  • How to Store, Retrieve & Delete data from HTML5 IndexedDB?
  • How to Export data from MySQL to Excel using PHP?
  • How a Web Development Company in New York helps…
  • ASP.NET Login page example with Remember me Option
  • ASP.NET File Upload to Server using FileUpload…
  • cPanel and hPanel? Ask your Hosting Provider before…
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

Diaper Change to Vaseline 10 Baby Circumcision after Care ideas
Diaper Change to Vaseline 10 Baby Circumcision after Care ideas
Circumcision refers to a standard procedure where the foreskin at the penis tip is removed surgically. Circumcision is usually done on a newborn boy within...
How Multivitamins are beneficial for Child to fill Nutritional Gap?
How Multivitamin are beneficial for Child to fill Nutritional Gap?
Your child may not be meeting their nutritional requirements despite your hardest attempts to do so. Due to their increasingly stressful and hectic schedule, parents...
Issues makes Kids Monitoring necessary for Parents
Issues makes Kids Monitoring necessary for Parents
The young generation, no doubt is the future of any county or state or any community. Therefore, it is very necessary to provide better facilities...
Reasons Why watching Anime is Great for Kids?
Reasons Why watching Anime is Great for Kids?
When kids are in their developmental phase, they get heavily influenced by the things that they spend their time with. It is the learning stage...
Skills Individuals Should Acquire after Completion of Child Care Courses
Skills Individuals Should Acquire after Completion of Child Care Courses
Completing Child Care Courses in Australia can be an excellent decision if you want to work with children in the future. You will gain adequate...
5 Reasons Why Outdoor Play is essential for Kids
5 Reasons Why Outdoor Play is essential for Kids
It’s no secret that outdoor play benefits kids of all ages. From providing physical activity to connecting with nature, the importance of outdoor play for children...

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.