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

Updates

  • An Email Marketing Strategy that Works for B2B
    •
  • How can eCommerce Strategies improve Customer Relationships?
    •
  • What are the best Strategies for Social Media Marketing?
    •
  • Everything you Should know about Hiring an Online Printing Service
    •
  • Plagiarism Checkers are Solution for Learning in Universities
    •
  • 10 Must-Have Apps for Entrepreneurs to Stay Organized
    •
  • 4 ways Learning Management System Can Transform your Business
    •
  • Why you Should Consider Hiring an Advertising Agency for your Business?
    •
  • How to make a Simple Iphone App and upload it in the App Store?
    •
  • Data Visualization’s Positive impression on Decision Making
    •
  • Everything you need to know related to Mail Forwarding Service
    •
  • Use of Etiquette to Short Sentences your Guide to Email Writing
    •
  • Why are Content Writing Services top Trending Now?
    •
  • Useful Tips Wrap Up your Blog with an effective Conclusion
    •
  • 4 Pros and 4 Cons of hiring Technical Writing Services
    •

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 82
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
  • 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…
  • How to display data from JSON to HTML table using PHP?
  • 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?
  • How to read JSON file data in JQuery? - GetJSON Example
  • JSON Tutorial for beginners - Learn JSON with Examples
  • What are Some Affordable Data Extraction Tools for…
  • What is the best Web Scraping Tool for Google Maps?
On-page SEO booster,
Google Friendly,
XML based
PHP/WP Sidebar
FREE Widgets
demo

Popular Categories

  • Miscellaneous591
  • Digitalization298
  • Career Guide243
  • Indian Blog207
  • Business Book177
  • Health & Wellness165
  • Travel & Tourism132
  • Your Financial Advisor116
  • Real Estate Consulting110
  • Shopping97
  • Blogging Techniques75
  • Digital Marketing70
  • Home Remedies70
  • SEO Techniques67
  • Programming62
  • Automobiles57

i20 Sidebar Widgets

Why it is Good for Every Senior Citizen to Buy Health Insurance?
Why it is Good for Every Senior Citizen to Buy Health Insurance?
Health issues might occur in human beings of all ages. However, older people are more prone to develop complicated diseases that need continuous medical supervision....
Dos and Donts of buying Health Insurance Cover for Family
Do’s and Don’ts of buying Health Insurance Cover for Family
Well-defined and comprehensive health insurance offers coverage to the policyholders for medical expenses in a medical emergency. A health insurance plan provides coverage for different...
What makes a Family Floater Health Insurance Plan the best in India?
What makes a Family Floater Health Insurance Plan the best in India?
Selecting the ideal health insurance policy for your family is a crucial financial choice. Among the many options available, family floater health insurance plans stand...
Individual vs Family vs Group Health Insurance Plans
Individual vs Family vs Group Health Insurance Plans
With the ever-growing cost of healthcare in the USA, finding the right health insurance plan that fits into your budget isn’t always easy. Knowing what...
Tips to Market Life Insurance Agency Online as an Adviser
Tips to Market Life Insurance Agency Online as an Adviser
Buying life insurance is one of the best ways to keep your family protected if they are financially dependent on you. When you are buying...
5 Must-have Features to include in a Maternity Insurance
5 Must-have Features to include in a Maternity Insurance
A family health plan that covers maternity insurance ensures that the family goes through a hassle free pregnancy especially when it comes to the financial...
How will a Term Insurance Policy help you with your Home Loan?
How will a Term Insurance Policy help you with your Home Loan?
Owning a house is nothing less than a dream come true for all of us. Whether it is big or small, we all try to...
Importance of Medical insurance for your Family
Importance of Medical insurance for your Family Members
We aspire to live a better life every day. And wish to provide a better, healthy, and comfortable life to our family. Taking care of...
What are the benefits of Insurance, Do I invest in Insurance?
What are the benefits of Insurance, Do I invest in Insurance?
Your world runs with Your Life. Life never back. In case of any accidental break Life Insurance gives stability to run your family. Insurance is...
Frequently Asked Questions about Car Insurance for Informed Decisions
Frequently Asked Questions about Car Insurance for Informed Decisions
Experts have been recommending buying as much auto insurance as one can actually afford. That advice may sound good but does not make any sense...

New Releases

The biggest Real Estate Investing Mistakes and How to Avoid them?
April 15, 2025

The biggest Real Estate Investing Mistakes and How to Avoid them?

Have you ever wondered if real estate investing is as straightforward as it sounds? Does the promise of steady rental income and rising property values…

Grow your Brand Empire with Elegant Custom Favor Boxes
April 11, 2025
Grow your Brand Empire with Elegant Custom Favor Boxes
How to Buy Facebook Likes and boost your Reach?
March 29, 2025
How to Buy Facebook Likes and boost your Reach?
Strategies for Reducing Pores - A Comprehensive Guide
March 28, 2025
Strategies for Reducing Pores – A Comprehensive Guide
The Ultimate Guide to Choosing the best Health Checkup Package for you
March 26, 2025
The Ultimate Guide to Choosing the best Health Checkup Package for you
Why my Organization or Our Products and Services need Guest Posting?
March 26, 2025
How paid Guest Posting Services helps Businesses to boost Sales?
How to use Multani Mitti? - Tips and Tricks for maximum Benefits
March 26, 2025
How to use Multani Mitti? – Tips and Tricks for maximum Benefits
Transform your Guest Room with a Multi-Functional Sofa Cum Bed
March 26, 2025
Transform your Guest Room with a Multi-Functional Sofa Cum Bed
CNC Machining in Model Making Dubai for Prototypes
March 21, 2025
CNC Machining in Model Making Dubai for Prototypes
How to Choose the Right Generator for your Home?
March 21, 2025
How to Choose the Right Generator for your Home?
How to Prepare for a Tummy Tuck in Islamabad?
March 19, 2025
How to Prepare for a Tummy Tuck in Islamabad?
Trump Towers 2 - Experience the Pinnacle of Luxury Living
March 15, 2025
Trump Towers 2 – Experience the Pinnacle of Luxury Living
Why Eye Cleaning is essential for your Health?
March 14, 2025
Why Eye Cleaning is essential for your Health?
From Local to Global - Digital Growth Strategies for Indian Brands
March 10, 2025
From Local to Global – Digital Growth Strategies for Indian Brands
Tattoo Booking App - Revolutionizing the Tattoo Industry
March 10, 2025
Tattoo Booking App – Revolutionizing the Tattoo Industry
Human Behavior in Men and Women Aged 18 to 35
March 10, 2025
Human Behavior in Men and Women Aged 18 to 35
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